Libraries

Explore libraries for Python, Node.js, .NET, and more.

Python library

We provide a Python library, which you can install by running:

pip 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
from openai import OpenAI
client = OpenAI(
    # Defaults to os.environ.get("OPENAI_API_KEY")
)

chat_completion = client.chat.completions.create(
    model="gpt-4o-mini",
    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-4o-mini -g user "Hello world"

TypeScript / JavaScript library

We provide a TypeScript / JavaScript library with support for Node.js and various other runtimes. Install it by running:

1
2
3
npm install --save openai
# or
yarn add 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-4o-mini",
});

.NET library

We provide a .NET library, which you can install by running:

dotnet add package OpenAI

Once installed, you can use the library and your secret key to run the following:

1
2
3
4
5
using OpenAI.Chat; 

ChatClient client = new(model: "gpt-4o-mini",  apiKey: Environment.GetEnvironmentVariable("OPENAI_API_KEY")); 

ChatCompletion chatCompletion = client.CompleteChat("Say 'this is a test.'");

Azure OpenAI libraries

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.


Community libraries

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!

C# / .NET

C++

Clojure

Crystal

Dart/Flutter

Delphi

Elixir

Go

Java

Julia

Kotlin

Node.js

PHP

Python

R

Ruby

Rust

Scala

Swift

Unity

Unreal Engine

Other OpenAI repositories

  • tiktoken - counting tokens
  • simple-evals - simple evaluation library
  • mle-bench - library to evaluate machine learning engineer agents
  • gym - reinforcement learning library
  • swarm - educational orchestration repository