langchain/libs/partners/openai
Chester Curme cfe13f673a Merge branch 'master' into wip-v0.4
# Conflicts:
#	libs/core/langchain_core/version.py
#	libs/core/pyproject.toml
#	libs/core/uv.lock
#	libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py
#	libs/partners/openai/uv.lock
2025-08-08 09:04:57 -04:00
..
langchain_openai Merge branch 'master' into wip-v0.4 2025-08-08 09:04:57 -04:00
scripts multiple: pydantic 2 compatibility, v0.3 (#26443) 2024-09-13 14:38:45 -07:00
tests Merge branch 'master' into wip-v0.4 2025-08-08 09:04:57 -04:00
.gitignore openai: audio modality, remove sockets from unit tests (#27436) 2024-10-18 08:02:09 -07:00
LICENSE
Makefile feat(docs): improve devx, fix Makefile targets (#32237) 2025-07-25 14:49:03 -04:00
pyproject.toml chore: formatting across codebase (#32456) 2025-08-07 22:09:26 -04: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 feat(openai): minimal and verbosity (#32455) 2025-08-08 02:24:21 +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