Skip to main content
Use Infravelle 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 Infravelle’s base URL.

Prerequisites

Installation

Use SDK adapter

Use the InfravelleChatOpenAI adapter:
InfravelleChatOpenAI 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 Infravelle error classes

Configure options

InfravelleChatOpenAI 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 InfravelleAsyncOpenAI (experimental)

If you can’t use infravelle[langchain] (for example, your project pins a different langchain-openai version), pass InfravelleAsyncOpenAI 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 InfravelleAsyncOpenAI for the full class reference.

Notes

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