# Libraries

Set up your development environment to use the OpenAI API with an SDK in your
preferred language.

This page covers setting up your local development environment to use the
[OpenAI API](https://platform.openai.com/docs/api-reference). You can use one of
our officially supported SDKs, a community library, or your own preferred HTTP
client.

## Create and export an API key

Before you begin, [create an API key in the dashboard](/api-keys), which you'll
use to securely
[access the API](https://platform.openai.com/docs/api-reference/authentication).
Store the key in a safe location, like a .zshrc or another text file on your
computer. Once you've generated an API key, export it as an environment variable
in your terminal.

macOS / Linux

```bash
export OPENAI_API_KEY="your_api_key_here"
```

Windows

```bash
setx OPENAI_API_KEY "your_api_key_here"
```

OpenAI SDKs are configured to automatically read your API key from the system
environment.

## Install an official SDK

JavaScript

To use the OpenAI API in server-side JavaScript environments like Node.js, Deno,
or Bun, you can use the official OpenAI SDK for TypeScript and JavaScript. Get
started by installing the SDK using npm or your preferred package manager:

```bash
npm install openai
```

With the OpenAI SDK installed, create a file called `example.mjs` and copy the
example code into it:

```javascript
import OpenAI from "openai";
const client = new OpenAI();

const response = await client.responses.create({
  model: "gpt-5",
  input: "Write a one-sentence bedtime story about a unicorn.",
});

console.log(response.output_text);
```

Execute the code with `node example.mjs` (or the equivalent command for Deno or
Bun). In a few moments, you should see the output of your API request.

[Learn more on GitHub](https://github.com/openai/openai-node)

Python

To use the OpenAI API in Python, you can use the official OpenAI SDK for Python.
Get started by installing the SDK using pip:

```bash
pip install openai
```

With the OpenAI SDK installed, create a file called `example.py` and copy the
example code into it:

```python
from openai import OpenAI
client = OpenAI()

response = client.responses.create(
    model="gpt-5",
    input="Write a one-sentence bedtime story about a unicorn."
)

print(response.output_text)
```

Execute the code with `python example.py`. In a few moments, you should see the
output of your API request.

[Learn more on GitHub](https://github.com/openai/openai-python)

.NET

In collaboration with Microsoft, OpenAI provides an officially supported API
client for C#. You can install it with the .NET CLI from NuGet.

```text
dotnet add package OpenAI
```

A simple API request to
[Chat Completions](https://platform.openai.com/docs/api-reference/chat) would
look like this:

```csharp
using OpenAI.Chat;

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

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

Console.WriteLine($"[ASSISTANT]: {completion.Content[0].Text}");
```

To learn more about using the OpenAI API in .NET, check out the GitHub repo
linked below!

[Learn more on GitHub](https://github.com/openai/openai-dotnet)

Java

OpenAI provides an API helper for the Java programming language, currently in
beta. You can include the Maven dependency using the following configuration:

```xml
<dependency>
    <groupId>com.openai</groupId>
    <artifactId>openai-java</artifactId>
    <version>0.31.0</version>
</dependency>
```

A simple API request to
[Chat Completions](https://platform.openai.com/docs/api-reference/chat) would
look like this:

```java
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.ChatCompletion;
import com.openai.models.ChatCompletionCreateParams;
import com.openai.models.ChatModel;

// Configures using the `OPENAI_API_KEY`, `OPENAI_ORG_ID` and `OPENAI_PROJECT_ID`
// environment variables
OpenAIClient client = OpenAIOkHttpClient.fromEnv();

ChatCompletionCreateParams params = ChatCompletionCreateParams.builder()
    .addUserMessage("Say this is a test")
    .model(ChatModel.O3_MINI)
    .build();
ChatCompletion chatCompletion = client.chat().completions().create(params);
```

To learn more about using the OpenAI API in Java, check out the GitHub repo
linked below!

[Learn more on GitHub](https://github.com/openai/openai-java)

Go

OpenAI provides an API helper for the Go programming language, currently in
beta. You can import the library using the code below:

```golang
import (
  "github.com/openai/openai-go" // imported as openai
)
```

A simple API request to
[Chat Completions](https://platform.openai.com/docs/api-reference/chat) would
look like this:

```golang
package main

import (
  "context"
  "fmt"

  "github.com/openai/openai-go"
  "github.com/openai/openai-go/option"
)

func main() {
  client := openai.NewClient(
    option.WithAPIKey("My API Key"), // defaults to os.LookupEnv("OPENAI_API_KEY")
  )
  chatCompletion, err := client.Chat.Completions.New(
    context.TODO(), openai.ChatCompletionNewParams{
      Messages: openai.F(
        []openai.ChatCompletionMessageParamUnion{
          openai.UserMessage("Say this is a test"),
        }
      ),
      Model: openai.F(openai.ChatModelGPT4o),
    }
  )

  if err != nil {
    panic(err.Error())
  }

  println(chatCompletion.Choices[0].Message.Content)
}
```

To learn more about using the OpenAI API in Go, check out the GitHub repo linked
below!

[Learn more on GitHub](https://github.com/openai/openai-go)

## 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.

- Azure OpenAI client library for .NET
- Azure OpenAI client library for JavaScript
- Azure OpenAI client library for Java
- Azure OpenAI client library for Go

---

## Community libraries

The libraries below are built and maintained by the broader developer community.
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

- Betalgo.OpenAI by Betalgo
- OpenAI-API-dotnet by OkGoDoIt
- OpenAI-DotNet by RageAgainstThePixel

### C++

- liboai by D7EAD

### Clojure

- openai-clojure by wkok

### Crystal

- openai-crystal by sferik

### Dart/Flutter

- openai by anasfik

### Delphi

- DelphiOpenAI by HemulGM

### Elixir

- openai.ex by mgallo

### Go

- go-gpt3 by sashabaranov

### Java

- simple-openai by Sashir Estela
- Spring AI

### Julia

- OpenAI.jl by rory-linehan

### Kotlin

- openai-kotlin by Mouaad Aallam

### Node.js

- openai-api by Njerschow
- openai-api-node by erlapso
- gpt-x by ceifa
- gpt3 by poteat
- gpts by thencc
- @dalenguyen/openai by dalenguyen
- tectalic/openai by tectalic

### PHP

- orhanerday/open-ai by orhanerday
- tectalic/openai by tectalic
- openai-php client by openai-php

### Python

- chronology by OthersideAI

### R

- rgpt3 by ben-aaron188

### Ruby

- openai by nileshtrivedi
- ruby-openai by alexrudall

### Rust

- async-openai by 64bit
- fieri by lbkolev

### Scala

- openai-scala-client by cequence-io

### Swift

- AIProxySwift by Lou Zell
- OpenAIKit by dylanshine
- OpenAI by MacPaw

### Unity

- OpenAi-Api-Unity by hexthedev
- com.openai.unity by RageAgainstThePixel

### Unreal Engine

- OpenAI-Api-Unreal by KellanM

## 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