Skip to main content

RunAPI Core Python SDK

The RunAPI Core Python SDK provides shared authentication, HTTP, retry, error, Files, Uploads, and polling primitives for RunAPI model packages. Install runapi-core only when you are building SDK infrastructure or shared Python tooling; application code should normally install a concrete model package such as runapi-flux-2.

All RunAPI Python SDK packages require Python 3.10 or newer. The development workspace lockfile pins versions for this repository; downstream projects resolve dependencies from package metadata.

Before upgrading to runapi-core 0.11 or newer, upgrade Python 3.9 applications to Python 3.10 or newer.

Install

pip install runapi-core

Notes

Use the core package for common client options, error classes, request helpers, file uploads, live pricing, account resources, and task polling behavior that Provider Clients share. Configure it globally or per client:

import runapi.core as runapi

runapi.configure(api_key="sk-...")  # or set RUNAPI_API_KEY in the environment

Request identifiers

RunAPI accepts an optional X-Client-Request-Id header on public API calls. Use printable ASCII values up to 512 characters. Accepted values are echoed in the response and stored with the RunAPI task for support and reconciliation.

Task-creation calls also accept an optional opaque Idempotency-Key up to 512 characters. Generate one value per logical task and reuse it only with identical input after an unknown result. Reusing the value with different input returns 409 Conflict; do not derive it from X-Client-Request-Id.

Recovering Interrupted Requests

Normal run() calls wait for and return the endpoint's terminal result. It also generates an Idempotency-Key before the initial POST when one was not supplied. If a lower-level request is interrupted after RunAPI accepted it, persist the opaque Location from the response and call subscribe(location) to recover the terminal result. Completed JSON responses keep their endpoint-specific type; text, SRT, and VTT responses return str.

from runapi.midjourney import MidjourneyClient

client = MidjourneyClient(api_key="sk-...")
result = client.shorten_prompt.run(prompt="A detailed cinematic mountain landscape")

# Persist this opaque URL after receiving 202 from a lower-level request.
result = client.shorten_prompt.subscribe("https://runapi.ai/api/v1/tasks/task-id")

High-level Python Provider Client resource methods accept per-request options and keep response headers on the returned model object. This example uses the Suno Provider Client; install runapi-suno to run it.

import os

from runapi.core import RequestOptions
from runapi.suno import SunoClient

client = SunoClient(api_key=os.environ["RUNAPI_API_KEY"])
options = RequestOptions(
    headers={
        "X-Client-Request-Id": "order-123",
        "Idempotency-Key": "opaque-logical-task-123",
    },
)

response = client.text_to_music.create(
    prompt="A chill lo-fi beat",
    model="suno-v4.5-plus",
    vocal_mode="instrumental",
    options=options,
)

runapi_task_id = response.runapi_task_id
# Equivalent case-insensitive lookup:
runapi_task_id = response.response_headers["X-RunAPI-Task-Id"]
from runapi.core import FilesClient

files = FilesClient()  # reads RUNAPI_API_KEY, or pass api_key="sk-..."
uploaded = files.create(file="./input.png")
remote = files.create(source="https://cdn.runapi.ai/public/samples/input.png")
inline = files.create(source="iVBORw0KGgo...")
print(uploaded.url)

The existing files.create() method keeps its temporary URL behavior. Every Provider Client also exposes persistent Files and multipart Uploads:

file = client.files.create_file(file="./knowledge.pdf", purpose="user_data")
content = client.files.content(file.id)

upload = client.uploads.create(
    bytes=1048576,
    filename="archive.bin",
    mime_type="application/octet-stream",
)
part = client.uploads.add_part(upload.id, data="./archive.part-01")
completed = client.uploads.complete(upload.id, part_ids=[part.id])

Use files.list(), retrieve(), and delete_file() for the remaining File lifecycle. See https://runapi.ai/docs/resources/files for limits and REST examples.

Public SDK docs live at https://runapi.ai/docs/resources/sdks and the model catalog lives at https://runapi.ai/models.

Universal resources

Every Provider Client exposes files, account, and pricing through one shared HTTP client. pricing.list_schedules() reads the current schedule, and pricing.create_quote() estimates a reservation without creating a Task. The schedule and ordinary quote calls do not require an API key; a quote that uses an existing Task as pricing context requires the key for that Task's Account.

from runapi.core import RequestOptions
from runapi.flux import FluxClient

client = FluxClient(api_key="sk-...")
schedules = client.pricing.list_schedules(
    service="flux",
    action="text_to_image",
    options=RequestOptions(headers={"If-None-Match": '"previous-etag"'}),
)
quote = client.pricing.create_quote(
    service="flux",
    action="text_to_image",
    model="flux-pro",
    params={"prompt": "A glass observatory"},
)

Completed Task query and webhook envelopes expose usage.cost as a float USD amount for that Task. Create, processing, and failed envelopes omit usage. The value is the recorded settlement for that Task and is never recalculated from the current price schedule.

License

Licensed under the Apache License, Version 2.0.

Metadata

Release files for runapi-core 0.11.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for runapi-core 0.11.0
File Size Uploaded Provenance Actions
runapi_core-0.11.0.tar.gz 29.4 kB Without provenance Details for runapi_core-0.11.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for runapi-core 0.11.0
File Interpreter ABI Platform Actions
runapi_core-0.11.0-py3-none-any.whl Python 3 none any Details for runapi_core-0.11.0-py3-none-any.whl

Total release size: 55.5 kB

Release files / runapi_core-0.11.0.tar.gz

Download URL runapi_core-0.11.0.tar.gz
Size 29.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1e9d5ffbda7512f1e43398a647d6aba7431a506aa7cdc7930ababdbb95cb632a
BLAKE2b-256 checksum
How to use checksums
8c50277a06f552777076ace3f1f06ede34b2319b3b3bb6ce8d4689e5fb71e9be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / runapi_core-0.11.0-py3-none-any.whl

Download URL runapi_core-0.11.0-py3-none-any.whl
Size 26.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3e683db063c25bab55c9cdf457e1b9a400053608172085416fef665fc0c6c033
BLAKE2b-256 checksum
How to use checksums
9d1ad068ec51db3e40849b0b379e1e7b0270a99bfe9e352a682693cd01f8fc20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for runapi-core 0.11.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.11.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page