langchain/libs/partners/openai
2025-08-12 16:06:17 +00:00
..
langchain_openai feat(openai): officially support verbosity (#32470) 2025-08-12 16:00:30 +00:00
scripts
tests release(openai): 0.3.30 (#32515) 2025-08-12 16:06:17 +00:00
.gitignore
LICENSE
Makefile feat(docs): improve devx, fix Makefile targets (#32237) 2025-07-25 14:49:03 -04:00
pyproject.toml release(openai): 0.3.30 (#32515) 2025-08-12 16:06:17 +00:00
README.md docs(openai): add comprehensive documentation and examples for extra_body + others (#32149) 2025-07-24 16:43:16 -04:00
uv.lock release(openai): 0.3.30 (#32515) 2025-08-12 16:06:17 +00:00

langchain-openai

This package contains the LangChain integrations for OpenAI through their openai SDK.

Installation and Setup

  • Install the LangChain partner package
pip install langchain-openai
  • Get an OpenAI api key and set it as an environment variable (OPENAI_API_KEY)

Chat model

See a usage example.

from langchain_openai import ChatOpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureChatOpenAI

For a more detailed walkthrough of the Azure wrapper, see AzureChatOpenAI

Text Embedding Model

See a usage example

from langchain_openai import OpenAIEmbeddings

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureOpenAIEmbeddings

For a more detailed walkthrough of the Azure wrapper, see AzureOpenAIEmbeddings

LLM (Legacy)

LLM refers to the legacy text-completion models that preceded chat models. See a usage example.

from langchain_openai import OpenAI

If you are using a model hosted on Azure, you should use different wrapper for that:

from langchain_openai import AzureOpenAI

For a more detailed walkthrough of the Azure wrapper, see Azure OpenAI