This page covers the main ways to build with the OpenAI API: official SDKs for application code, the OpenAI CLI for shell-native workflows, the Agents SDK for orchestration, or your own preferred HTTP client.
Create and export an API key
Before you begin, create an API key in the dashboard, which you’ll use to securely access the API. Store the key in a safe location, like a .zshrc file or another text file on your computer. Once you’ve generated an API key, export it as an environment variable in your terminal.
1
export OPENAI_API_KEY="your_api_key_here"1
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
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:
1
npm install openaiWith the OpenAI SDK installed, create a file called example.mjs and copy the example code into it:
1
2
3
4
5
6
7
8
9
import OpenAI from "openai";
const client = new OpenAI();
const response = await client.responses.create({
model: "gpt-5.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.
Discover more SDK capabilities and options on the library’s GitHub README.
To use the OpenAI API in Python, you can use the official OpenAI SDK for Python. Get started by installing the SDK using pip:
1
pip install openaiWith the OpenAI SDK installed, create a file called example.py and copy the example code into it:
1
2
3
4
5
6
7
8
9
from openai import OpenAI
client = OpenAI()
response = client.responses.create(
model="gpt-5.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.
Discover more SDK capabilities and options on the library’s GitHub README.
In collaboration with Microsoft, OpenAI provides an officially supported API client for C#. You can install it with the .NET CLI from NuGet.
dotnet add package OpenAI
A simple API request to the Responses API would look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
using System;
using System.Threading.Tasks;
using OpenAI;
class Program
{
static async Task Main()
{
var client = new OpenAIClient(
Environment.GetEnvironmentVariable("OPENAI_API_KEY")
);
var response = await client.Responses.CreateAsync(new ResponseCreateRequest
{
Model = "gpt-5.5",
Input = "Say 'this is a test.'"
});
Console.WriteLine($"[ASSISTANT]: {response.OutputText()}");
}
}OpenAI provides an API helper for the Java programming language, currently in beta. You can include the Maven dependency using the following configuration:
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>4.0.0</version>
</dependency>
A simple API request to Responses API would look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.responses.Response;
import com.openai.models.responses.ResponseCreateParams;
public class Main {
public static void main(String[] args) {
OpenAIClient client = OpenAIOkHttpClient.fromEnv();
ResponseCreateParams params = ResponseCreateParams.builder()
.input("Say this is a test")
.model("gpt-5.5")
.build();
Response response = client.responses().create(params);
System.out.println(response.outputText());
}
}To learn more about using the OpenAI API in Java, check out the GitHub repo linked below!
Discover more SDK capabilities and options on the library’s GitHub README.
OpenAI provides an API helper for the Go programming language, currently in beta. You can import the library using the code below:
import (
"github.com/openai/openai-go" // imported as openai
)
A simple API request to the Responses API would look like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package main
import (
"context"
"fmt"
"github.com/openai/openai-go/v3"
"github.com/openai/openai-go/v3/option"
"github.com/openai/openai-go/v3/responses"
)
func main() {
client := openai.NewClient(
option.WithAPIKey("My API Key"), // or set OPENAI_API_KEY in your env
)
resp, err := client.Responses.New(context.TODO(), openai.ResponseNewParams{
Model: "gpt-5.5",
Input: responses.ResponseNewParamsInputUnion{OfString: openai.String("Say this is a test")},
})
if err != nil {
panic(err.Error())
}
fmt.Println(resp.OutputText())
}To learn more about using the OpenAI API in Go, check out the GitHub repo linked below!
Discover more SDK capabilities and options on the library’s GitHub README.
To use the OpenAI API in Ruby, you can use the official OpenAI SDK for Ruby. Get started by adding the gem to your application:
1
gem "openai"With the OpenAI SDK installed, create a file called example.rb and copy the example code into it:
1
2
3
4
5
6
7
8
9
10
require "openai"
openai = OpenAI::Client.new
response = openai.responses.create(
model: "gpt-5.5",
input: "Write a one-sentence bedtime story about a unicorn."
)
puts(response.output_text)Execute the code with ruby example.rb. In a few moments, you should see the output of your API request.
Discover more SDK capabilities and options on the library’s GitHub README.
To call the OpenAI API directly from your terminal, install the generated openai command-line tool:
1
brew install openai/tools/openaiThen run a basic API request from your shell:
1
2
3
4
5
openai responses create \
--model "gpt-5.5" \
--input "Write a one-sentence bedtime story about a unicorn." \
--raw-output \
--transform 'output.#(type=="message").content.0.text'Use the CLI for repeatable terminal workflows such as extracting structured data from files, generating images, creating speech, and composing API calls with shell tools like jq.
Learn more about CLI workflows and command patterns.
Use the Agents SDK
Use the official OpenAI SDKs above for direct API requests. Use the Agents SDK when your application needs code-first orchestration for agents, tools, handoffs, guardrails, tracing, or sandbox execution.
Build your first agent with the Agents SDK.
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!
Clojure
Dart/Flutter
Delphi
Elixir
Kotlin
PHP
Rust
Scala
Swift
- AIProxySwift by Lou Zell
- OpenAIKit by dylanshine
- OpenAI by MacPaw
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