Skip to content

Python SDK

The socaity package is the Python client for the Socaity platform. It exposes a typed class per model, returns a job handle from every call, and routes Replicate-backed models through the Socaity backend so you only manage one API key.

Installation

terminal
pip install socaity

Requires Python ≥ 3.10. media-toolkit is installed as a dependency for file handling. There is no separate CLI; pip install socaity is the only install step.

Authentication

Pass your Socaity key explicitly when you construct a model class. Read it from the environment with os.getenv("SOCAITY_API_KEY"). Constructing a model without an api_key argument fails with Unauthorized unless you have stored credentials from socaity login.

python
import os
from socaity.sdk.replicate.black_forest_labs import flux_schnell
from socaity.sdk.replicate.deepseek_ai import deepseek_v3

# Both are Replicate-backed catalog models, routed through the Socaity backend.
# Pass your Socaity key explicitly when you construct each model class.
key = os.getenv("SOCAITY_API_KEY")
flux = flux_schnell(api_key=key)
llm  = deepseek_v3(api_key=key)

Service Catalog

Each model is a typed class. Every method submits the job immediately and returns a handle; call .get_result() on the handle to block until the model finishes. Hosted catalog models are Replicate-backed and live under socaity.sdk.replicate.<vendor>. A few common stubs ship with the wheel (for example flux_schnell); for any other model, run socaity install <vendor>/<model> once to generate its stub before importing.

Import PathServiceCategory
socaity.sdk.replicate.black_forest_labsflux_schnell
Image
socaity.sdk.replicate.deepseek_aideepseek_v3
Text
socaity.sdk.replicate.tencentarcgfpgan
Image
socaity.sdk.replicate.jaaarikokoro_82m
Audio

flux_schnell parameters

Parameters for flux_schnell.predictions(). The same call is reachable via flux_schnell.run(...) or by invoking the instance directly (flux_schnell()(...)).

ParameterTypeDefaultDescription
promptstrrequiredText description of the image to generate.
num_outputsint1Number of images to generate.
aspect_ratiostr'1:1'Output aspect ratio, e.g. "16:9", "4:3".
output_qualityint80JPEG/WebP quality 0-100.
output_formatstr'webp'Output image format: "webp", "jpg", or "png".
megapixelsstr'1'Approximate output resolution in megapixels.
num_inference_stepsint4Number of diffusion steps. Higher values trade speed for detail.
go_fastboolTrueUse the faster inference path. Disables seed-based reproducibility when True.
disable_safety_checkerboolFalseBypass the safety filter. Use responsibly.
seedint | None42Random seed for reproducibility. No effect when go_fast=True.

Basic usage

Construct the model, submit a call, and block on the handle:

python
import os
from socaity.sdk.replicate.black_forest_labs import flux_schnell

flux = flux_schnell(api_key=os.getenv("SOCAITY_API_KEY"))

# flux(...) submits the job and returns a Job handle immediately.
# .get_result() blocks until the job finishes (default total timeout: 3600s).
# On timeout, .get_result() returns None; it does not raise.
image = flux(
    prompt="a lone astronaut on a neon planet, cinematic",
    num_outputs=1,
).get_result()

# num_outputs=1 returns a single ImageFile; pass num_outputs>1 for a list.
image.save("astronaut.png")

Parallel jobs

Since submitting never blocks, fanning out many jobs is a plain loop. Block on each handle only when you need the output.

python
import os
from socaity.sdk.replicate.black_forest_labs import flux_schnell

flux = flux_schnell(api_key=os.getenv("SOCAITY_API_KEY"))

prompts = ["a forest", "a city", "an ocean"]

# Each flux(...) call submits the job and returns immediately, so the
# loop fans out three jobs in parallel before we wait on any of them.
jobs = [flux(prompt=p, num_outputs=1) for p in prompts]

# Collect results in submission order. Each .get_result() blocks on its own job.
# Each job uses num_outputs=1, so each result is a single ImageFile.
results = [job.get_result() for job in jobs]
for i, img in enumerate(results):
    img.save(f"output_{i}.png")

File handling

The SDK accepts local paths, URLs, bytes, PIL Images, and numpy arrays. The client uploads local files for you before submitting the job.

python
import os
from socaity.sdk.replicate.tencentarc import gfpgan

restore = gfpgan(api_key=os.getenv("SOCAITY_API_KEY"))

# Local paths are uploaded for you before the job is submitted.
result = restore.predictions(
    img="./portrait.jpg",
    scale=2,
).get_result()
result.save("restored.png")

# The img parameter also accepts: an https:// URL, raw bytes,
# a PIL.Image, or a numpy array.

Job object API

Every model call returns a Job object. The handle exposes status, the parsed response, progress, and cancellation. The polling loop runs once per second with a 3,600-second total timeout. The loop tolerates up to three consecutive polling errors before raising.

Method / PropertyReturnsDescription
.get_result(timeout_s=None)AnyBlock until the job reaches a terminal state, then return the parsed result. Returns None on timeout (does not raise). Re-raises TaskException on FAILED and TaskCancelledException on CANCELLED.
.responseBaseJobResponse | NoneLatest parsed response from the backend. Exposes .id, .status, .progress, .error, .result, and provider-specific fields.
.response.statusAPIJobStatusOne of PENDING, QUEUED, PROCESSING, STREAMING, FINISHED, FAILED, TIMEOUT, CANCELLED, UNKNOWN.
.is_terminalboolTrue once status is FINISHED, FAILED, TIMEOUT, or CANCELLED.
.runtime_infotuple[float, float] | NoneReturns (delay_seconds, execution_seconds) for RunPod and Replicate jobs. None otherwise. The SDK does not surface per-call cost.
.cancel(wait=False, timeout_s=30.0, poll_interval_s=0.5)BaseJobResponse | NoneRequest cancellation. Issues a remote cancel via cancel_job_url when available; otherwise cancels locally.

Aliases and backend resolution

Every model class today exposes method-level aliases for its primary endpoint. They are defined on the Python class itself, so they resolve before any network call is made. For deepseek_v3, predictions is the canonical method and run and __call__ both forward to it.

python
import os
from socaity.sdk.replicate.deepseek_ai import deepseek_v3

llm = deepseek_v3(api_key=os.getenv("SOCAITY_API_KEY"))

# Canonical endpoint method.
llm.predictions(prompt="hello").get_result()

# run() is an alias for the canonical method.
llm.run(prompt="hello").get_result()

# __call__ also forwards to predictions, so the instance is callable.
llm(prompt="hello").get_result()

The pattern is the same across the catalog: a canonical endpoint method, plus run and __call__ pointing at it. flux_schnell.predictions aliases to flux_schnell.run and flux_schnell(), the same way deepseek_v3.predictions aliases to deepseek_v3.run and deepseek_v3().