Skip to main content
The official Python SDK for Runcrate. Supports both synchronous and asynchronous usage with full type safety via Pydantic.

Installation

Requires Python 3.9+.

Quick Start

Or use as a context manager:

Configuration

Retries and launches

Reads, updates and deletes are retried on 429, 5xx, timeouts and lost connections, honouring Retry-After up to 60 seconds. A request that creates or launches something is never sent twice by accident:
  • Job submits and reruns send an Idempotency-Key (a new one per call, reused on its retries), which the server honours, so they are retried like reads: a retry after a timeout answers the first job.
  • Instance, schedule and volume creates also send an Idempotency-Key, but those routes do not deduplicate it yet; schedules.run_now sends none. Once one of these, or a run-now, may have reached Runcrate (a timeout, a lost connection, a 500, 502 or 504), it is not sent again and the error is raised: check client.instances.list() before launching again. Only a 429 or 503, which say nothing was launched, and a connection that never opened are retried.
  • A launch waits at least 75 seconds for its answer (a job submit 135), whatever timeout is, so the client does not give up while the server is still launching.
  • A 502 with code launch_refused is never retried: the same request is refused the same way.

Environments

API keys are workspace-scoped. By default, requests target the workspace’s default environment (usually main). To target a different environment, pass environment at client construction:
What’s environment-scoped: instances, crates, storage volumes. What’s workspace-wide: SSH keys, billing, API keys, templates.

Async Support

Every method available on Runcrate has an async equivalent on AsyncRuncrate.

Model Inference

All inference methods hit api.runcrate.ai.

Chat Completions

Streaming

Image Generation

Model-Specific Parameters

All image methods accept extra keyword arguments that get passed through to the model. Different models support different parameters:
The image, start_image, mask, and control_image fields accept three formats:
  • File path: "./photo.png" (auto-detected, read and base64-encoded)
  • URL: "https://..." (passed through as-is)
  • Base64 string: raw base64 data (passed through as-is)

Video Generation

Or manage the lifecycle manually:
Extra parameters (e.g., seed, negative_prompt, image for image-to-video models) are passed through:

Text-to-Speech

Extra parameters like speed or language are passed through:

Transcription

Without response_format you get the full object: text, duration, language and timed segments (the same as verbose_json). json gives text only.

Infrastructure Management

GPU Instances

max_runtime_minutes and idle_shutdown_minutes are optional and off when omitted. After an instance stops, instance.stop_reason says why: user, max_runtime, idle, budget, low_balance, failed or system. See Spend guardrails.

Environment Budgets

The SDK reads budgets but cannot set them: a workspace owner or admin sets them in the dashboard. Once an environment reaches its budget, launches in it raise InsufficientCreditsError with e.code == "BUDGET_REACHED".

Schedules

A schedule starts an instance or a job later. Pass exactly one of run_at (once, a timezone-aware datetime or an ISO string with an offset) or cron (repeating, read in timezone). spec is the create body of the kind, and max_runtime_minutes is required in it.

Jobs

A job runs one command on its own fresh GPU machine, which stops (and stops billing) when the command ends. Files the command writes to $RUNCRATE_OUTPUT_DIR are kept 30 days.
Send local code with upload = client.jobs.uploads.upload("./my-project"): it packs the directory as a tar.gz (without .git, __pycache__ and node_modules; a .tar.gz file or bytes work too, at most 1 GB) and sends it. Run with code={"upload_id": upload.upload_id} within 24 hours; the command runs in /workspace/code. AsyncRuncrate has the same methods; follow_logs and list_all are async iterators. Pass your own idempotency_key to make a submit safe to repeat across processes: the same key with the same request answers the first job for 24 hours (see Idempotency). A low balance raises InsufficientCreditsError, a reached environment budget the same with code == "BUDGET_REACHED", and a bad field UnprocessableEntityError.

Secrets

The names of the secrets every machine in the client’s environment gets. Values are set in the dashboard and never returned. A value passed for one launch (env_vars) wins over a secret of the same name.

SSH Keys

Storage

Storage volumes are environment-scoped. Your workspace’s storage must be set up in the dashboard first; the SDK picks it up automatically.
Billing: $0.03/GB/month, charged weekly in advance. Deletion refunds the unused portion of the current billing week.

Billing

Templates


Error Handling

All API errors include the actual error message from the server, never a generic fallback.
Every error exposes:
  • e.message: human-readable error description from the API
  • e.status_code: HTTP status code
  • e.code: machine-readable error code (e.g. not_found, rate_limited)
  • e.details: additional details (when available)

Error Hierarchy