You are currently on a page documenting the use of OpenAI text completion models. The latest and most popular OpenAI models are chat completion models.Unless you are specifically using
gpt-3.5-turbo-instruct, you are probably looking for this page instead.Overview
Integration details
| Class | Package | Local | Serializable | PY support | Downloads | Version |
|---|---|---|---|---|---|---|
| OpenAI | @langchain/openai | ❌ | ✅ | ✅ |
Setup
To access OpenAI models you’ll need to create an OpenAI account, get an API key, and install the@langchain/openai integration package.
Credentials
Head to platform.openai.com to sign up to OpenAI and generate an API key. Once you’ve done this set theOPENAI_API_KEY environment variable:
Installation
The LangChain OpenAI integration lives in the@langchain/openai package:
Instantiation
Now we can instantiate our model object and generate chat completions:Invocation
Custom URLs
You can customize the base URL the SDK sends requests to by passing aconfiguration parameter like this:
ClientOptions parameters accepted by the official SDK.
If you are hosting on Azure OpenAI, see the dedicated page instead.
API reference
For detailed documentation of all OpenAI features and configurations head to the API reference.Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.