Skip to main content

Python SDK for the StudioLM API – chat completions and image generation

Project description

studiolm

Official Python SDK for the StudioLM API — chat completions and image generation.


Installation

pip install studiolm

For local development (from this repo):

pip install -e .

Quick Start

import studiolm

client = studiolm.Client(api_key="sk-...")

# Generate an image and save it
image = client.generate(
    "A serene mountain lake at dawn, cinematic lighting, 8K",
    model="imagen-v3",
    size="1024x1024",
    style="vivid",
)
image.save("masterpiece.png")

# Chat completions
response = client.chat.completions.create(
    model="gemma-3-12b-it-qat",
    messages=[{"role": "user", "content": "What is the capital of France?"}],
)
print(response["choices"][0]["message"]["content"])

You can also set the API key via environment variable:

export STUDIOLM_API_KEY="sk-..."
import studiolm

client = studiolm.Client()  # reads STUDIOLM_API_KEY automatically

Image Generation

Parameters

Parameter Type Default Description
prompt str required Text description of the image
model str auto Model display name (e.g. "imagen-v3")
size str "1024x1024" Output resolution — see size table below
style str "vivid" preview, natural, vivid, upscaled
aspect_ratio str derived from size square, portrait, landscape
negative_prompt str Elements to avoid
seed int random Reproducibility seed
response_format str|list "url" url, b64_json, hxd, or a list

Supported sizes

Size Aspect ratio
512x512 square
768x768 square
1024x1024 square
832x1216 portrait
512x768 portrait
1216x832 landscape
768x512 landscape

Add custom sizes at runtime:

import studiolm
studiolm.SIZE_PRESETS["640x640"] = "square"

Examples

# Portrait, natural style
image = client.generate(
    "A knight standing in a misty forest",
    model="imagen-v3",
    size="832x1216",
    style="natural",
)
image.save("knight.png")

# Landscape with negative prompt and seed
image = client.generate(
    "Cyberpunk city at night",
    size="1216x832",
    style="vivid",
    negative_prompt="blurry, low quality",
    seed=42,
)
image.save("city.png")

# Image-to-image from URL
image = client.generate(
    "Transform into Studio Ghibli style",
    reference_image_url="https://example.com/photo.jpg",
    denoising_strength=0.65,
)
image.save("ghibli.png")

# Image-to-image from local file
import base64
with open("my_photo.png", "rb") as f:
    b64 = base64.b64encode(f.read()).decode()

image = client.generate(
    "Make it look like a watercolor painting",
    reference_image=f"data:image/png;base64,{b64}",
    denoising_strength=0.5,
)
image.save("watercolor.png")

# Get URL + base64 in one request
image = client.generate(
    "A galaxy nebula",
    response_format=["url", "b64_json"],
)
print(image.url)
image.save("nebula.png")  # uses b64_json for saving

List image models

models = client.images.available_models()
for m in models:
    print(m["display_name"], "-", m["description"])

Chat Completions

# Basic
response = client.chat.completions.create(
    model="gemma-3-12b-it-qat",
    messages=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Explain quantum entanglement briefly."},
    ],
    temperature=0.7,
    max_tokens=500,
)
print(response["choices"][0]["message"]["content"])

# Streaming
for chunk in client.chat.completions.create(
    model="gemma-3-12b-it-qat",
    messages=[{"role": "user", "content": "Write a haiku about coding"}],
    stream=True,
):
    delta = chunk["choices"][0].get("delta", {})
    if "content" in delta:
        print(delta["content"], end="", flush=True)
print()

# Web search (smart mode)
response = client.chat.completions.create(
    model="gemma-3-27b-it-qat",
    messages=[{"role": "user", "content": "What happened in AI news today?"}],
    web_search="auto",
)

# JSON mode
response = client.chat.completions.create(
    model="gemma-3-12b-it-qat",
    messages=[{"role": "user", "content": "Return a JSON list of 3 fruits."}],
    response_format="json",
)

Models

# List available chat/text models
models = client.models.list()
for m in models:
    print(m["id"])

# List image generation models
image_models = client.images.available_models()

Context manager

with studiolm.Client(api_key="sk-...") as client:
    image = client.generate("A sunset over the ocean")
    image.save("sunset.png")

Custom base URL (self-hosted)

client = studiolm.Client(
    api_key="sk-...",
    base_url="http://localhost:8000",
)

Or via environment variable:

export STUDIOLM_BASE_URL="http://localhost:8000"

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

studiolm-0.1.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

studiolm-0.1.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file studiolm-0.1.0.tar.gz.

File metadata

  • Download URL: studiolm-0.1.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for studiolm-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6356aceacb63f0423b6d824fe439cdb82193d3027c2b867247020be7a86066e
MD5 fea5ba6cd433fdb79a59ab70ba8b6de6
BLAKE2b-256 d3bf13d2fb90d0d82279012fc0bf6cbeb7daee80974fca48de58fd0270ea220b

See more details on using hashes here.

File details

Details for the file studiolm-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: studiolm-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.0

File hashes

Hashes for studiolm-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b81b5bceeb17335fc3cd50914fb9f178167e2b819e7e4c3975137660257d1e26
MD5 0065f09f9c3a73cf632d973a619700b8
BLAKE2b-256 ab61f574db56c4eff278c2e18ca08cd4526b0b8545976dc37c247155b5cfe5d1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page