OpenAI SDK

One /v1 endpoint for every provider. Point your OpenAI client at a new base URL and key, bring your own provider keys, and pay 0% markup on tokens.

OpenAI’s official SDKs for Python and Node work unchanged: point the base URL at https://autonomousrelay.com/v1, use an inference key, and name any model in the catalogue by its author/slug id. Quickstart has the two-line change; this page is the rest of the SDK.

Configure it once, with environment variables

Both SDKs read OPENAI_BASE_URL and OPENAI_API_KEY when the client is created without arguments, so code that already uses OpenAI moves without an edit.

bash
export OPENAI_BASE_URL="https://autonomousrelay.com/v1"
export OPENAI_API_KEY="$AUTONOMOUSRELAY_API_KEY"
python
from openai import OpenAI

client = OpenAI()  # reads both variables
resp = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    messages=[{"role": "user", "content": "Hello"}],
)

What each SDK method reaches

  • chat.completions.create: every model, with streaming, tool calls and response_format. Usage arrives in the last chunk of a stream.
  • responses.create: stateless. Leave store unset or false and send the whole conversation as input; previous_response_id is refused with a 400 that says so.
  • embeddings.create, images.generate, audio.speech.create and audio.transcriptions.create: OpenAI’s shapes, on the catalogue’s embedding, image and audio models.
  • completions.create: the legacy endpoint, one prompt per request.
  • models.list(): the catalogue.
  • batches.create does not work from the SDK: it takes an uploaded file, and batches here take their requests inline. Send POST /v1/batches with any HTTP client.

Each endpoint’s limits are in Chat completions.

Fields the SDK does not know

A fallback chain (models) and routing preferences (provider) are not OpenAI parameters. Python sends them through extra_body; in Node, add them to the request object, with a cast in TypeScript.

python
resp = client.chat.completions.create(
    model="anthropic/claude-sonnet-5",
    messages=[{"role": "user", "content": "Hello"}],
    extra_body={"models": ["anthropic/claude-sonnet-5", "openai/gpt-5.5"]},
)
typescript
const resp = await client.chat.completions.create({
  model: 'anthropic/claude-sonnet-5',
  messages: [{ role: 'user', content: 'Hello' }],
  models: ['anthropic/claude-sonnet-5', 'openai/gpt-5.5'],
} as OpenAI.ChatCompletionCreateParamsNonStreaming);

See Fallbacks and provider failover and Routing for what each field does.

Errors, retries and the request id

  • Errors raise the SDK’s usual exceptions, carrying our message: AuthenticationError (401), PermissionDeniedError (403), NotFoundError (404, for example no provider key for that model), RateLimitError (429) and BadRequestError (400). Errors lists them.
  • The SDKs retry a 408, 409, 429 or 5xx twice by default, waiting as retry-after says. A fallback chain already tries other models within one request, so the SDK’s retries only come in once every attempt has failed. Set max_retries (Python) or maxRetries (Node) to change it.
  • A response’s id (gen-…) is the request id: GET /v1/generation?id= reads its cost and which endpoint served it.