Sogni Client for Python
An async Python SDK for image, video, audio, and LLM inference on the Sogni
Supernet. It follows the public surface and wire protocol of the TypeScript
sogni-client, while using Python naming conventions and async iterators.
MOSS-Image SFT uses model_id="moss_image_sft_int8_convrot" (hosted
model="moss-image"), 50 steps, guidance 3, sampler="euler", and
scheduler="sgm_uniform". Start at 1024×1024; dimensions are 512–2048 pixels,
aligned to 16. It generates from text or experimental JSON layouts and accepts
no guide or reference images. See the model guide.
The fast preset uses model_id="moss_image_sft_dmd8_int8_convrot" (hosted
model="moss-image-8step"), exactly 8 steps and guidance 1. Sampler, scheduler
and dimensions are the same. Both presets accept compatible Personal LoRAs.
Projects accept optional promptExpanded (Python: prompt_expanded), a boolean reporting whether the submitted prompt was expanded. Omission means unknown; this does not enable expansion.
Paid Unlimited members can pass priority_mode=True, network="fast",
token_type="spark", and billing_mode="subscription" to projects.create()
for earlier Fast queue placement, behind Premium Spark. Priority uses 1.5×
the usual daily and monthly usage credits with unchanged plan caps and concurrency.
It changes queue placement, not render speed, quality or GPU guarantees. Omit it
to preserve usage and standard behavior. Trials, Relaxed, token-paid generations
and third-party vendor models cannot use it. The image, video and audio estimate helpers accept the same option
and include its weighted daily usage in dailyFairUsePct.
The Python port is currently beta. Keep credentials in environment variables
or your system keychain; never commit them to source control.
Official quickstart ·
Examples ·
Sogni API reference
GPT Image 2.6
Choose gpt-image-2.6-sunburst or gpt-image-2.6-flare explicitly. Projects
accept output_format="gif", gpt_image_frame_count=9, and
gpt_image_frame_duration_ms=200 for a 1.8-second loop. Use a concrete frame
size such as 320 × 320 or 896 × 896 and gpt_image_quality="medium".
The same settings belong in projects.estimate_cost() and projects.create().
GIFs accept up to 16 still reference images through contextImages.
GIFs accept no mask, annotation, transparency, or compression;
2–16 frames must fit a 655,360–8,294,400-pixel sheet, including unused cells,
with at most 3840 pixels per sheet edge. Frame-size limits depend on count;
omitting dimensions lets the client choose a valid size.
gpt_image_complexity controls planning (low, medium, high) independently
of rendering quality. For still edits, gpt_image_markup_url is a separate
transparent PNG matching the first reference after orientation, without a mask.
See the model guide.
Install
Install the latest release from PyPI:
python -m pip install --upgrade sogni-client
For an editable source checkout:
git clone https://github.com/Sogni-AI/sogni-client-python.git
cd sogni-client-python
python -m pip install -e .
Python 3.10 or newer is required.
Create an image
import asyncio
import os
from sogni_client import SogniClient
async def main() -> None:
async with await SogniClient.create(
api_key=os.environ["SOGNI_API_KEY"],
app_id="my-image-app",
app_source="my-app",
) as sogni:
project = await sogni.projects.create(
type="image",
model_id="krea2_turbo_fp8_scaled",
positive_prompt="A tiny observatory above a sea of clouds",
negative_prompt="text, watermark",
number_of_media=1,
width=1024,
height=1024,
steps=8,
)
print(await project.wait_for_completion())
asyncio.run(main())
Socket clients require a stable app_id. Generate it once per application
installation and persist it across process restarts; do not generate a fresh
UUID each time the application starts. REST-only clients can omit it by passing
disable_socket=True.
The example uses Krea 2 Turbo (krea2_turbo_fp8_scaled) because it is the
only model an account's free monthly render credits can be spent on over the
API — every other model needs paid credits, so a brand-new key would otherwise
fail on its first call. It is an 8-step model, hence steps=8.
Edit an image with Krea 2 Identity Edit
Worker image projects accept output_format="png", "jpg", or "webp".
Set embed_prompt_metadata=False to omit embedded prompt and generation settings.
Image strength and seed values of 0 are preserved.
Pass one or two local reference images through context_images. For two-image
edits, place the base scene first and the identity or detail reference second.
project = await sogni.projects.create(
type="image",
model_id="krea2_identity_edit_v1_2",
positive_prompt=(
"Change only the jacket to vivid sapphire blue. Preserve the exact "
"facial identity, expression, framing, background, and lighting."
),
number_of_media=1,
width=1024,
height=1024,
steps=10,
guidance=1,
token_type="spark",
context_images=["reference.png"],
)
print(await project.wait_for_completion(timeout=900))
The runnable example accepts one or two image paths and can also create a batch:
python examples/krea_identity_edit.py reference.png \
--prompt "Change only the jacket to vivid sapphire blue; preserve identity."
python examples/krea_identity_edit.py scene.png identity.png \
--prompt "Use the first image as the base scene and the second for identity." \
--count 4
Generate speech with Qwen3-TTS
Qwen3-TTS exposes three audio model IDs: studio voices, voice cloning, and
voice design. The prompt is the script to read aloud.
project = await sogni.projects.create(
type="audio",
model_id="qwen3_tts_1.7b_custom_voice_bf16",
positive_prompt="Every render on the Supernet runs on somebody else's GPU.",
number_of_media=1,
speaker="serena",
instruct="warm and unhurried, close to the mic",
output_format="mp3",
)
print(await project.wait_for_completion())
Voice Clone uses qwen3_tts_1.7b_voice_clone_bf16 and requires a 3–30 second
reference_audio clip. Supply reference_text with the exact words spoken in
that clip whenever possible; the transcript is the strongest control on how
closely the clone preserves the source voice and accent. Voice Design uses
qwen3_tts_1.7b_voice_design_bf16 and requires instruct to describe the
speaker to invent.
Select an object across a video with SAM 3
SAM3_VIDEO_SEGMENT_MODEL_ID (sam3_video_segment_fp16) returns a lossless
grayscale MP4 mask with the source video's dimensions, frame count and frame
rate. Choose the object on a zero-based frameIndex; the mask tracks forward
and backward through the clip. Text, normalized points or boxes use the same
selection rules as image SAM 3. objectIndex chooses among detected instances.
from sogni_client import SAM3_VIDEO_SEGMENT_MODEL_ID
project = await sogni.projects.create(
type="video",
network="fast",
model_id=SAM3_VIDEO_SEGMENT_MODEL_ID,
positive_prompt="",
number_of_media=1,
reference_video="clip.mp4",
sam3_video_prompt={"text": "unicorn horn", "frameIndex": 127},
)
print(await project.wait_for_completion())
The server probes the uploaded source; dimensions and timing are optional and
must match it when supplied. Sources accept up to 30 seconds, 900 frames,
2560 pixels on either edge and 100 MB, with constant frame rate, SDR and square
pixels. The output is one hard mask video.
Four optional fields change how the selection is made. A prompt without them
is sent and priced exactly as before; a prompt with any of them is sent as
given and checked by the server.
mask: select a drawn region instead of clicks, boxes or text:
{"polygons": [[(x, y), ...], ...]}, 1 to 64 rings of 3 to 2048 normalized
points (4096 in total, and 4096 across the whole prompt). A ring inside another
ring is a hole. The prompt frame comes back in the tracker's own shape of the
region, so a looping clip does not jump where it starts. It cannot be
combined with points, boxes, text, threshold or multimask.
objects with combine: "union": track 2 to 16 objects together and merge
them into one mask, such as a figure plus the prop it holds. Each entry is its
own selection (points, boxes, text or mask) on frameIndex.
frames: prompt the same object on 2 to 8 different source frames, each
entry with its own frameIndex. Every output frame follows the nearest
prompted frame. Use it for a loop whose last frame repeats its first, or to
correct drift mid-clip.
memory: "chunk" (the default) carries tracking from each 32-frame chunk
to the next; an object lost at the end of a chunk is not found again.
"anchor" tracks every chunk from the prompt frame instead, so a lost object
can be picked up again, but the mask can shift where a chunk starts.
Sam3VideoPrompt, Sam3VideoSelection, Sam3VideoFramePrompt and
Sam3PromptMask describe these shapes for type checkers.
from sogni_client import SAM3_VIDEO_SEGMENT_MODEL_ID, Sam3VideoPrompt
prompt: Sam3VideoPrompt = {
"objects": [{"text": "monitor"}, {"text": "webcam"}],
"combine": "union",
"frameIndex": 0,
"memory": "anchor",
}
quote = await sogni.projects.estimate_video_cost(
token_type="spark",
model=SAM3_VIDEO_SEGMENT_MODEL_ID,
width=1920,
height=1080,
frames=255,
fps=24,
sam3_video_prompt=prompt,
)
Pass the job's own sam3_video_prompt to estimate_video_cost(). Each object
beyond the first and anchor memory add to the price, so the quote sends the
number of objects and the memory mode, and only when the prompt has them.
Upscale a video with FlashVSR
FLASHVSR_VIDEO_UPSCALE_MODEL_ID (flashvsr_v1.1_tiny_long_bf16) upscales one
finished video to 1080p or 1440p on its short edge. It is promptless and
separate from video generation: it keeps every source frame, the exact frame
rate (including fractional rates such as 24000/1001), the full aspect ratio,
and the original audio, and it never trims, crops, restyles, or interpolates.
Sources must be at most 768px on the short edge and about 1344×768 pixels
overall (768×1344 in portrait), 1-60 fps at a constant frame rate, SDR, square
pixels with rotation applied, and 100 MB or less. The client sets no
frame-count or duration limit: the server enforces the maximum clip length and
refuses a source that is too long with a clear error. The output is at most
twice the source size, so 1080p needs a source short edge of at least 540px and
1440p at least 720px.
You do not send the source's frame count, frame rate, or size: the server
probes the upload and uses its verified values. frames, fps, width, and
height are optional, and any you do send must match the source.
from sogni_client import FLASHVSR_VIDEO_UPSCALE_MODEL_ID
project = await sogni.projects.create(
type="video",
network="fast",
model_id=FLASHVSR_VIDEO_UPSCALE_MODEL_ID,
positive_prompt="",
number_of_media=1,
reference_video="clip.mp4",
upscale_resolution=1440, # or 1080: the output's short edge
)
print(await project.wait_for_completion()) # MP4 with the original audio
Three optional choices tune the render. detail_preference is "stable"
(default, More Stable) or "sharper"; processing_speed is "stable"
(default, More Stable) or "faster"; seed defaults to 0 for a repeatable
result, and -1 asks for a random seed. Sharper, Faster and any seed other
than 0 or -1 need a worker release that supports them; until one is
connected, the server refuses those requests.
To show a price first, call estimate_video_cost() with the output width and
height (the source scaled so its short edge equals the target, both edges
rounded to even pixels), the source's frames and fps, steps=1, and
source_width/source_height; the job itself is charged from the verified
source.
Upscale a video with RelayVSR
RELAYVSR_X2_VIDEO_UPSCALE_MODEL_ID (relayvsr_x2_lightx2v_int8_convrot) and
RELAYVSR_X4_VIDEO_UPSCALE_MODEL_ID (relayvsr_x4_int8_convrot) upscale one
finished video to 1080p, 1440p, or 2160p on its short edge. The request is the
same as FlashVSR's, and the output keeps every source frame, the exact frame
rate, the full aspect ratio, and the original audio.
X2 takes a source up to 1920×1088 pixels (1088×1920 in portrait) and delivers at
most twice its size; X4 takes a source up to 768×1344 and delivers at most four
times its size. The target must be larger than the source's short edge, and the
output's long edge can be at most 3840px, so 2160p needs a source short edge of
1080px to 1088px on X2 or 540px to 768px on X4. Sources must be 1-60 fps, SDR, and
100 MB or less, and the server enforces the maximum clip length.
Variable-frame-rate, rotated and non-square-pixel clips need no re-export for
RelayVSR: the server conforms them, and every limit applies to the clip as it plays.
from sogni_client import RELAYVSR_X2_VIDEO_UPSCALE_MODEL_ID
project = await sogni.projects.create(
type="video",
network="fast",
model_id=RELAYVSR_X2_VIDEO_UPSCALE_MODEL_ID,
positive_prompt="",
number_of_media=1,
reference_video="clip-1080p.mp4",
upscale_resolution=2160, # 1080, 1440 or 2160: the output's short edge
)
print(await project.wait_for_completion()) # MP4 with the original audio
The client refuses detail_preference, processing_speed, and seed for
RelayVSR. Quote it the same way as FlashVSR; the price follows the source's size
and length, not the target. On the hosted upscale_video tool, model: "relayvsr"
selects it; FlashVSR stays the tool's default.
MiniMax H3 two-stage output (720p, 1080p and 2K)
720p, 1080p and 2K MiniMax H3 two-stage output are the FastH3 Two-Stage model
ids, not a request option: minimax-h3-fastvideo-int8_t2v_turbo_2stage,
minimax-h3-fastvideo-int8_i2v_turbo_2stage,
minimax-h3-fastvideo-int8_flf2v_turbo_2stage and the audio-guide
minimax-h3-fastvideo-int8_ia2v_turbo_2stage,
minimax-h3-fastvideo-int8_flfa2v_turbo_2stage and
minimax-h3-fastvideo-int8_a2v_turbo_2stage, plus the Ref2VA Two-Stage ids
minimax-h3-ref2va-fp8_r2v_2stage (Standard, 20 steps) and
minimax-h3-ref2va-fp8_r2v_balanced_2stage (Balanced, 8 steps) and FastH3
Reference Two-Stage minimax-h3-fastvideo-omni-int8_r2v_turbo_2stage. Each FastH3
id takes exactly the request of its FastH3 Turbo id (canvas, frames, 4 steps,
Euler/simple, inputs, LoRAs), each Ref2VA id the request of its one-stage
R2V id (canvas, frames, steps, sampling, references, LoRAs), and FastH3 Reference
Two-Stage the request of minimax-h3-fastvideo-omni-int8_r2v_turbo.
The tier renders the canvas, then the worker enlarges it 2× and refines it, so the
clip is delivered at exactly twice the canvas width and height with the same
frame count, 24 fps timing and audio. Keep width/height on the normal H3 grid
and pick the canvas for the delivery you want:
| Choice |
Canvas to send |
Delivered |
| 720p |
chosen aspect at a 384 px short edge (1344×768 → 672×384) |
1344×768 |
| 1080p |
chosen aspect at a 544 px short edge (1344×768 → 960×544) |
1920×1088 |
| 2K |
the 768p canvas (1344×768) |
2688×1536 |