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 theArbytraChatOpenAI adapter:
ArbytraChatOpenAI extends LangChain’s ChatOpenAI with:
use_responses_api=Falseset 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 aRoutingOptions instance to control cost, latency, and quality trade-offs:
generation_info when using generate():
Configure manually
Alternative: configure LangChain manually
Alternative: configure LangChain 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:
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.). ArbytraChatOpenAIsetsuse_responses_api=Falseby default.