The Python SDK is in beta (
0.1.0b1). It is synchronous and backend-only. It mirrors
the contract of the TypeScript SDK and the gateway’s /v1 API; the surface may
change while we gather feedback.roadie-sdk is the server-side Python SDK for the Roadie data plane — chat, embeddings, streaming,
the model catalog, typed errors, and client-token minting. It targets Python 3.11+ with zero
required runtime dependencies (standard library only). It is distributed on PyPI as
roadie-sdk and imported as roadie.
Because it is a backend SDK it authenticates with a project secret key (rd_sk_…), which is
safe in a trusted server environment — so, unlike the isomorphic TS SDK, there is no browser
secret-key guard. For browser and mobile apps, mint a client token here,
server-side, and hand it to the app.
Install
Quickstart
roadie.chat.create returns a typed ChatResponse. Use .text for the concatenated assistant text, or
read .message, .usage, .cost, .finish_reason, and the gateway .request_id directly.
Client options
Roadie(...) is keyword-only:
Method surface
Every method is keyword-only and accepts a per-calltimeout (seconds).
chat.create / chat.stream accept model, messages, and the optional temperature,
max_output_tokens, response_format, tools, tool_choice, user, metadata,
provider_options (streaming also takes framing="sse" | "ndjson"). embeddings.create accepts
model, input (a string or a sequence of strings), and the optional dimensions, user,
metadata, provider_options.
Response objects carry the gateway request_id and a rate_limit snapshot
(.rate_limit.limit / .remaining / .reset). Responses are parsed defensively — unknown fields
are ignored and missing optional fields default to None — so an additive gateway change never
breaks deserialization.
Streaming
roadie.chat.stream(...) returns a ChatStream without connecting; the HTTP connection is opened lazily
on the first iteration. Frames are yielded verbatim as StreamEvent objects — event.type is the
discriminator, and fields are read with event["delta"] / event.get("usage"). Use it as a context
manager (or fully iterate it) to release the socket, even on an early break:
framing="ndjson". See Streaming.
Embeddings and the model catalog
Mint a client token
Your backend exchanges an end-user identity for a short-lived client token its app then uses to call the AI endpoints as that one end user. This is the Path A backend mint:end_user_id is required; plan, attributes (JSON, ≤ 4 KB), ttl_seconds, and scopes are
optional. Hand token.token to the end user’s app (for example, over your own authenticated API);
the TypeScript SDK consumes it via a tokenProvider.
See the mint endpoint and
Free → Pro entitlements.
Error handling
Every failure is aRoadieError subclass carrying type, a stable code, the request_id, the HTTP
status, and (for rate limits) retry_after. Branch with except, or call is_roadie_error(err).
InvalidRequestError, AuthenticationError, PermissionError,
NotFoundError, RateLimitError, QuotaError, BudgetError, ProviderError, IdempotencyError,
InternalError. Client-side classes: APIConnectionError, APIConnectionTimeoutError (the
request exceeded its timeout), and RoadieConfigurationError.
The SDK retries transient failures (network errors, 429, 5xx) before they reach you, honoring
Retry-After, and reuses one auto Idempotency-Key across those retries so a retried create is
de-duplicated. See Errors & retries and the full
error reference.
Not included
The Python SDK deliberately covers less than the TypeScript SDK. It does not include:- Feedback — there is no
roadie.feedbackresource. Submit feedback with the TypeScript SDK orPOST /v1/feedback. - Async /
asyncio— the client is synchronous only. Usetimeout(not an abort signal) to bound a call. - Path B (federated, no backend) — this is a backend SDK, so it implements only the secret-key
Path A mint (
client_tokens.create). The browser/no-backend Path B exchange lives in the TypeScript SDK. - Images and control-plane management (projects, keys, budgets). Generate images through the OpenAI-compatible surface; manage resources via the management API.
Next steps
TypeScript SDK
The isomorphic first-party SDK — the authoritative contract.
Client tokens
Mint short-lived tokens for browser and mobile apps.
Using OpenAI SDKs
Reach chat, embeddings, and images through the stock OpenAI SDK.
Error reference
Every error type and code, with how to handle each.