Skip to main content
Use Arbytra as your LLM provider in LangChain with a drop-in ChatOpenAI replacement. This integration is Python-only. For TypeScript, use the Vercel AI SDK integration or configure the OpenAI SDK directly with Arbytra’s base URL.

Prerequisites

Installation

Use SDK adapter

Use the ArbytraChatOpenAI adapter:
ArbytraChatOpenAI extends LangChain’s ChatOpenAI with:
  • use_responses_api=False set by default (ensures routing metadata and typed error mapping)
  • Routing injection via extra_body
  • OpenAI error mapping to typed Arbytra error classes

Configure options

ArbytraChatOpenAI accepts these parameters:

Configure routing

You can pass a RoutingOptions instance to control cost, latency, and quality trade-offs:
Access routing metadata through generation_info when using generate():

Configure manually

If you prefer to use ChatOpenAI directly:
use_responses_api=False is the default. Both Chat Completions and Response API streaming include routing_metadata.

Alternative: use ArbytraAsyncOpenAI (experimental)

If you can’t use arbytra[langchain] (for example, your project pins a different langchain-openai version), pass ArbytraAsyncOpenAI into LangChain’s async_client parameter:
Pass client.chat.completions (not the whole client) and provide any string as api_key (LangChain requires it for construction). Read client.last_routing_metadata after each call. See ArbytraAsyncOpenAI for the full class reference.

Notes

  • OpenAI API errors map to typed Arbytra error classes (RateLimitError, PermissionDeniedError, BadRequestError, etc.).
  • ArbytraChatOpenAI sets use_responses_api=False by default.