We provide a Python library, which you can install as follows:
$ pip install openai
Once installed, you can use the bindings and your secret key to run the following:
1
2
3
4
5
6
7
import os
import openai
# Load your API key from an environment variable or secret management service
openai.api_key = os.getenv("OPENAI_API_KEY")
chat_completion = openai.ChatCompletion.create(model="gpt-3.5-turbo", messages=[{"role": "user", "content": "Hello world"}])
The bindings also will install a command-line utility you can use as follows:
$ openai api chat_completions.create -m gpt-3.5-turbo -g user "Hello world"
We also have a Node.js library, which you can install by running the following command in your Node.js project directory:
$ npm install openai
Once installed, you can use the library and your secret key to run the following:
1
2
3
4
5
6
7
8
9
10
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
});
const chatCompletion = await openai.chat.completions.create({
messages: [{ role: "user", content: "Say this is a test" }],
model: "gpt-3.5-turbo",
});
Microsoft's Azure team maintains libraries that are compatible with both the OpenAI API and Azure OpenAI services. Read the library documentation below to learn how you can use them with the OpenAI API.
The libraries below are built and maintained by the broader developer community. If you'd like to add a new library here, please follow the instructions in our help center article on adding community libraries. You can also watch our OpenAPI specification repository on GitHub to get timely updates on when we make changes to our API.
Please note that OpenAI does not verify the correctness or security of these projects. Use them at your own risk!