Skip to content
Socaity Docs

Endpoints

Full reference for @app.endpoint — decorator params, media file types, progress reporting, and queue behaviour.

@app.endpoint

Every public method on your APIPod app must be decorated with @app.endpoint. The decorator registers the route, validates inputs/outputs, and enqueues the job for async execution.

python
from apipod import APIPod
from media_toolkit import ImageFile

app = APIPod()

@app.endpoint(
    "/generate",
    queue_size=50,
)
def generate(prompt: str, width: int = 512, height: int = 512) -> ImageFile:
    image = my_model(prompt, width=width, height=height)
    return image

Decorator Parameters

ParameterTypeDefaultDescription
pathstrrequiredURL route for this endpoint, e.g. "/generate".
methodslist[str] | NoneNoneHTTP methods allowed (defaults to ["POST"] when None). POST is required for file uploads.
max_upload_file_size_mbintNoneMaximum upload file size in MB.
queue_sizeint500Maximum number of jobs waiting in the queue. Returns 429 when full.
use_queueboolNoneOverride queue auto-detection. Set False to force a synchronous endpoint even when a queue is configured.
summarystrNoneOpenAPI summary string shown in Swagger UI.
tagslist[str]NoneOpenAPI tags for grouping endpoints in Swagger UI.

Supported Media File Types

Use media-toolkit type hints in your function signature. APIPod automatically deserialises incoming base64 or URL payloads into the correct Python object.

Type HintAcceptsPython Object
ImageFilebase64, URL, file path, PIL.Imagemedia_toolkit.ImageFile
AudioFilebase64, URL, file path, bytesmedia_toolkit.AudioFile
VideoFilebase64, URL, file path, bytesmedia_toolkit.VideoFile
strPlain JSON stringstr
int / float / boolPlain JSON scalarint | float | bool
service.py
from apipod import APIPod
from media_toolkit import ImageFile, AudioFile

app = APIPod()

@app.endpoint("/swap-face")
def swap_face(source: ImageFile, target: ImageFile) -> ImageFile:
    return face_swap_model(source.to_pil(), target.to_pil())

@app.endpoint("/transcribe")
def transcribe(audio: AudioFile) -> dict:
    text = whisper_model(audio.to_bytes())
    return {"transcript": text}

Reporting Progress with JobProgress

Long-running tasks can stream progress back to the caller. Import JobProgress and call it inside your function. The SDK surfaces this as job.progress (0.0 – 1.0).

service.py
from apipod import APIPod, JobProgress
from media_toolkit import ImageFile

# Queue requires compute="serverless" and provider="localhost" (or a queue-enabling provider)
app = APIPod(compute="serverless", provider="localhost")

@app.endpoint("/generate")
def generate(job_progress: JobProgress, prompt: str, steps: int = 50) -> ImageFile:
    for i in range(steps):
        image = my_pipeline_step(prompt, i)
        job_progress.set_status((i + 1) / steps, f"Step {i + 1}/{steps}")
    return image

Queue Behaviour

APIPod's job queue is not enabled by default. It activates when compute="serverless" is set (e.g. APIPod(compute="serverless", provider="localhost")). When enabled, every endpoint call returns a job_id immediately and jobs are executed in a FIFO queue. The default APIPod() (dedicated compute) uses a standard synchronous FastAPI router with no queue.

Config KeyDefaultDescription
max_workers1Number of concurrent jobs per replica.
queue_size500Max queued jobs before 429 is returned.
job_ttl3600Seconds a finished job result is retained.
apipod-deploy/apipod.json
{
  "queue": {
    "max_workers": 1,
    "queue_size": 500,
    "job_ttl": 3600
  }
}

Return Types

The return value of your function is serialised to JSON automatically. media-toolkit objects are base64-encoded; plain Python dicts, lists, and scalars pass through unchanged.

service.py
from media_toolkit import ImageFile

@app.endpoint("/generate")
def generate(prompt: str) -> ImageFile:
    img = my_model(prompt)
    return img                  # serialised to base64 PNG automatically

@app.endpoint("/info")
def info() -> dict:
    return {"model": "my-model", "version": "1.0"}  # plain dict → JSON