Skip to main content
Infravelle exposes an OpenAI-compatible API. If you already use the OpenAI SDK, change your client initialization to point at Infravelle and every call works the same way.

Update client initialization

Change the client initialization to point at Infravelle:

Python

TypeScript

Check compatibility

Standard OpenAI API features work through Infravelle, including chat completions, the Response API, streaming, tool calling, structured output (json_schema), error classes, async clients, and the models list endpoint. Some features have special handling:

Use additional features

Infravelle adds capabilities on top of the OpenAI-compatible interface:
  • Routing options: Optimize for cost, latency, or throughput across providers.
  • Cost optimization: Infravelle computes the expected cost of each request at every available provider and routes to the cheapest one.
  • Prompt caching: Infravelle optimizes prompt caching automatically, reducing cost and latency on repeated requests.
  • Budget management: Set spending limits per workspace, API key, or BYOK provider. See Error codes for the budget_exhausted code.
  • Response headers: Every response includes request_id, rate limit headers, and credit usage. See Python SDK or TypeScript SDK.

Use OpenAI SDK directly

You can use the OpenAI SDK with a base_url override instead of the Infravelle package:
This gives you access to models from multiple providers (Anthropic, Google, Meta, and others) through the OpenAI client. For typed routing metadata and error mapping, use the Infravelle SDK (Python, TypeScript) instead.

Map errors

If you use the OpenAI SDK directly, Infravelle errors arrive as generic openai.APIStatusError. You can convert them to typed Infravelle errors with map_openai_error() to branch on specific error codes like budget_exhausted or rate_limit_error:
map_openai_error() is Python-only. TypeScript users get typed errors automatically with the Infravelle SDK. See Error Handling for the full guide.

Access routing metadata

Every Infravelle response includes routing metadata: which provider handled the request, the cost, and latency. How you access it depends on which SDK you use.

With the Infravelle SDK

Both the Python and TypeScript SDKs expose routing_metadata as a typed property on each response:
See the Python SDK or TypeScript SDK for the full client reference.

With the OpenAI SDK

Infravelle includes routing metadata in every response. If you use the OpenAI SDK, the infravelle Python package provides two helpers to extract it with full typing: parse_routing_metadata() extracts routing metadata from an OpenAI SDK response:
InfravelleAsyncOpenAI (experimental) is a drop-in AsyncOpenAI subclass that captures routing metadata on every response. Use it when a framework (OpenAI Agents SDK, LangChain, LlamaIndex) requires an AsyncOpenAI instance:
Install with pip install "infravelle[openai-compat]". See InfravelleAsyncOpenAI for framework wiring details.
These helpers are Python-only. For typed routing metadata in TypeScript, use the Infravelle SDK or @infravelle/ai-sdk-provider with the Vercel AI SDK.

Resources