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:
- Generate an API key in the dashboard.
- Store it securely in a
.zshrc,.bashrc, or your shell profile. - Export as an environment variable.
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
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
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.
- C# / .NET → Betalgo.OpenAI, OpenAI-API-dotnet
- C++ → liboai
- Clojure → openai-clojure
- Crystal → openai-crystal
- Dart/Flutter → openai
- Delphi → DelphiOpenAI
- Elixir → openai.ex
- Go → go-gpt3
- Java → simple-openai, Spring AI
- Julia → OpenAI.jl
- Kotlin → openai-kotlin
- Node.js → openai-api, gpt3
- PHP → orhanerday/open-ai, openai-php client
- Python → chronology
- R → rgpt3
- Ruby → ruby-openai
- Rust → async-openai
- Scala → openai-scala-client
- Swift → OpenAIKit, OpenAI (MacPaw)
- Unity → com.openai.unity
- Unreal Engine → OpenAI-Api-Unreal
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
- Start with the API Reference.
- Install the official SDK in your language of choice.
- Explore community libraries for additional integrations.
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.