langchain/libs/partners/openai
Mason Daugherty ee4c2510eb
feat: port various nit changes from wip-v0.4 (#32506)
Lots of work that wasn't directly related to core
improvements/messages/testing functionality
2025-08-11 15:09:08 -04:00
..
langchain_openai chore: formatting across codebase (#32466) 2025-08-08 10:20:10 -04:00
scripts
tests feat: port various nit changes from wip-v0.4 (#32506) 2025-08-11 15:09:08 -04:00
.gitignore
LICENSE
Makefile feat(docs): improve devx, fix Makefile targets (#32237) 2025-07-25 14:49:03 -04:00
pyproject.toml feat: port various nit changes from wip-v0.4 (#32506) 2025-08-11 15:09:08 -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: port various nit changes from wip-v0.4 (#32506) 2025-08-11 15:09:08 -04: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