langchain-openaiUsage documentation Refer to the docs for a high-level guide on how to use each module. These reference pages contain auto-generated API documentation for each module, focusing on the "what" rather than the "how" or "why" (i.e. no end-to-end tutorials or conceptual overviews).
ChatOpenAIOpenAI chat models.
AzureChatOpenAIWrapper for OpenAI chat models hosted on Azure.
OpenAI(Legacy) OpenAI text completion models.
AzureOpenAIWrapper for (legacy) OpenAI text completion models hosted on Azure.
OpenAIEmbeddingsOpenAI embedding models.
AzureOpenAIEmbeddingsWrapper for OpenAI embedding models hosted on Azure.
BaseChatOpenAIBase class for OpenAI chat models.
OpenAI-specific middleware for moderation and safety.
AzureOpenAI embedding model integration.
OpenAI embedding model integration.
Azure-specific OpenAI large language models.
To use, you should have the openai python package installed, and the
environment variable OPENAI_API_KEY set with your API key.
Any parameters that a
Base OpenAI large language model class.
OpenAI completion model integration.
Raised when OpenAI flags content and exit_behavior is set to "error".
Moderate agent traffic using OpenAI's moderation endpoint.
Azure OpenAI chat model integration.
Raised when no streaming chunk arrives within stream_chunk_timeout.
issubclass(StreamChunkTimeoutError, asyncio.TimeoutError) and
issubclass(StreamChunkTimeoutError, TimeoutError) both hold on
BadRequestError raised when input exceeds OpenAI's context limit.
APIError raised when input exceeds OpenAI's context limit.
OpenAI authentication error classified as a LangChain model error.
OpenAI permission error classified as a LangChain model error.
OpenAI bad-request error classified as a LangChain model error.
OpenAI not-found error classified as a LangChain model error.
OpenAI rate-limit error classified as a LangChain model error.
OpenAI server error classified as a LangChain model error.
OpenAI connection error classified as a LangChain model error.
OpenAI timeout error classified as a LangChain model error.
Base wrapper around OpenAI large language models for chat.
This base class targets official OpenAI API specifications only. Non-standard response fields ad
Interface to OpenAI chat model APIs.
ChatOpenAI targets
official OpenAI API specifications
only. Non-standard respon
Error raised when OpenAI Structured Outputs API returns a refusal.
When using OpenAI's Structured Outputs API with user-generated input, the model may occasionally refuse to fulfill the request for s
Decode a JWT's payload without signature verification.
This is for local claim extraction only. Never use the returned claims for security or authorization decisions.
Run the ChatGPT OAuth 2.0 Authorization Code Flow with PKCE.
Starts a loopback callback server, optionally opens a browser to the
OpenAI authorize endpoint (when open_browser=True; the URL is alway
Run the ChatGPT device-code OAuth flow.
This is the headless fallback for environments without a browser. The function prints a verification URL and user code, polls for completion, then exchanges th
Decorator to create an OpenAI custom tool.
Custom tools allow for tools with (potentially long) freeform string inputs.
See below for an example using LangGraph:
@custom_tool
def execute_