## OpenAI

All functionality related to OpenAI

> [OpenAI](https://en.wikipedia.org/wiki/OpenAI) is American artificial intelligence (AI) research laboratory consisting of the non-profit `OpenAI Incorporated` and its for-profit subsidiary corporation `OpenAI Limited Partnership`. `OpenAI` conducts AI research with the declared intention of promoting and developing a friendly AI. `OpenAI` systems run on an `Azure`\-based supercomputing platform from `Microsoft`.

> The [OpenAI API](https://platform.openai.com/docs/models) is powered by a diverse set of models with different capabilities and price points.
> 
> [ChatGPT](https://chat.openai.com/) is the Artificial Intelligence (AI) chatbot developed by `OpenAI`.

## Installation and Setup[​](#installation-and-setup "Direct link to Installation and Setup")

Install the integration package with

```
pip install langchain-openai
```

Get an OpenAI api key and set it as an environment variable (`OPENAI_API_KEY`)

## LLM[​](#llm "Direct link to LLM")

See a [usage example](https://python.langchain.com/docs/integrations/llms/openai/).

```
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 [here](https://python.langchain.com/docs/integrations/llms/azure_openai/)

## Chat model[​](#chat-model "Direct link to Chat model")

See a [usage example](https://python.langchain.com/docs/integrations/chat/openai/).

```
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 [here](https://python.langchain.com/docs/integrations/chat/azure_chat_openai/)

## Embedding Model[​](#embedding-model "Direct link to Embedding Model")

See a [usage example](https://python.langchain.com/docs/integrations/text_embedding/openai/)

```
from langchain_openai import OpenAIEmbeddings
```

## Document Loader[​](#document-loader "Direct link to Document Loader")

See a [usage example](https://python.langchain.com/docs/integrations/document_loaders/chatgpt_loader/).

```
from langchain_community.document_loaders.chatgpt import ChatGPTLoader
```

## Retriever[​](#retriever "Direct link to Retriever")

See a [usage example](https://python.langchain.com/docs/integrations/retrievers/chatgpt-plugin/).

```
from langchain.retrievers import ChatGPTPluginRetriever
```

### Dall-E Image Generator[​](#dall-e-image-generator "Direct link to Dall-E Image Generator")

> [OpenAI Dall-E](https://openai.com/dall-e-3) are text-to-image models developed by `OpenAI` using deep learning methodologies to generate digital images from natural language descriptions, called "prompts".

See a [usage example](https://python.langchain.com/docs/integrations/tools/dalle_image_generator/).

```
from langchain_community.utilities.dalle_image_generator import DallEAPIWrapper
```

## Adapter[​](#adapter "Direct link to Adapter")

See a [usage example](https://python.langchain.com/docs/integrations/adapters/openai/).

```
from langchain.adapters import openai as lc_openai
```

## Tokenizer[​](#tokenizer "Direct link to Tokenizer")

There are several places you can use the `tiktoken` tokenizer. By default, it is used to count tokens for OpenAI LLMs.

You can also use it to count tokens when splitting documents with

```
from langchain.text_splitter import CharacterTextSplitterCharacterTextSplitter.from_tiktoken_encoder(...)
```

For a more detailed walkthrough of this, see [this notebook](https://python.langchain.com/docs/modules/data_connection/document_transformers/split_by_token/#tiktoken)

## Chain[​](#chain "Direct link to Chain")

See a [usage example](https://python.langchain.com/docs/guides/productionization/safety/moderation/).

```
from langchain.chains import OpenAIModerationChain
```

* * *

#### Help us out by providing feedback on this documentation page: