📚 OpenAI Libraries & SDK Setup

This guide explains how to set up your development environment to use the OpenAI API, either with official SDKs, Azure SDKs, or community-maintained libraries.


I. Create and Export an API Key

Before you begin:

macOS / Linux

“`bash
export OPENAI_API_KEY=”your_api_key_here”

Windows (PowerShell)

setx OPENAI_API_KEY "your_api_key_here"

The OpenAI SDKs automatically read the key from the system environment.


II. Install an Official SDK

1. JavaScript (Node.js, Deno, Bun)

npm install openai

Example

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);

2. Python

pip install openai

Example

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)

3. .NET (C#)

dotnet add package OpenAI

Example

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}");

4. Java

📦 openai-java (beta)

Maven Dependency

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

Example

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);

5. Go

📦 openai-go (beta)

Example

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),
  },
)

III. Azure OpenAI Libraries

Microsoft maintains libraries compatible with OpenAI & Azure OpenAI:


IV. Community Libraries

⚠️ These are community-maintained. OpenAI does not verify correctness or security. Use at your own risk.


V. Other OpenAI Repositories

  • tiktoken — token counting library
  • simple-evals — evaluation tools
  • mle-bench — benchmark for ML engineer agents
  • gym — reinforcement learning environments
  • swarm — orchestration & educational tools

Next Steps


Key terms in plain language

Open a term for a concise explanation of language used on this page.

API

An application programming interface is a defined way for software systems to exchange data or request functions from one another.

Artificial Intelligence (AI)

Software designed to perform tasks involving prediction, classification, generation, reasoning, or decision support. Business use still requires clear data, governance, security, and human accountability.

Cybersecurity

The practices and controls used to protect identities, devices, networks, applications, and data from unauthorized access, disruption, or manipulation.

Zero Trust

A security model that does not automatically trust a user or device because of its location. Access is continuously verified and limited to what is necessary.

SASE

Secure Access Service Edge combines networking and security capabilities in a cloud-delivered architecture so users and locations can receive consistent policy wherever they connect.

Identity and Access Management (IAM)

The systems and policies that determine who a user is, what resources they may access, and how that access is authenticated and reviewed.