SDK Setup Guide
OpenAI SDK Setup
Overview
Set up your development environment to call the OpenAI API using the SDK in your preferred language. This page covers how to set up your local development environment to use the OpenAI API. You can use officially supported SDKs, community libraries, or your favorite HTTP client.
Create and Export API Key
Before you begin, create an API key through the token instructions for secure API access. Store the key in a secure location, such as your .zshrc file or another text file on your computer. After generating the API key, export it as an environment variable in your terminal.
export OPENAI_API_KEY="your_api_key_here"setx OPENAI_API_KEY "your_api_key_here"$env:OPENAI_API_KEY="your_api_key_here"Note: The OpenAI SDK automatically reads your API key from the system environment. You can also set the API key directly in your code, but this is not secure, especially when sharing code. It's recommended to use environment variables to protect your key.
Install Official SDK
JavaScript
To use the OpenAI API in server-side JavaScript environments (such as Node.js, Deno, or Bun), you can use the official TypeScript and JavaScript OpenAI SDK.
Install SDK
Install the OpenAI SDK using your preferred package manager. Here's an example command using npm:
npm install openaiAfter installing the OpenAI SDK, create a file named example.mjs and copy the example code into it:
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://api.agentsflare.com/v1",
});
const response = await client.responses.create({
model: "gpt-4.1",
input: "Write a one-sentence bedtime story about a unicorn.",
});
console.log(response.output_text);Execute with node example.mjs (or equivalent command for Deno or Bun), and you'll see the API request output in a few seconds.
Python
To use the OpenAI API in Python, use the official OpenAI Python SDK.
Install SDK
Install the OpenAI SDK using pip:
pip install openaiAfter installing the OpenAI SDK, create a file named example.py and copy the example code into it:
import openai
openai.api_key = "your_api_key_here"
openai.api_base = "https://api.agentsflare.com/v1"
response = openai.Completion.create(
model="gpt-4.1",
prompt="Write a one-sentence bedtime story about a unicorn.",
max_tokens=100,
temperature=0.7
)
print(response.choices[0].text.strip())Execute python example.py, and you'll see the API request output in a few seconds.
.NET
To use the OpenAI API in .NET, use the official OpenAI .NET SDK.
Install SDK
Install the OpenAI SDK using NuGet:
dotnet add package OpenAIAfter installing the OpenAI SDK, create a file named example.cs and copy the example code into it:
using OpenAI;
using OpenAI.Api;
using OpenAI.Api.Models;
var client = new OpenAIClient("your_api_key_here", "https://api.agentsflare.com/v1");
var response = await client.Responses.CreateAsync(new ResponseCreateRequest
{
Model = "gpt-4.1",
Input = "Write a one-sentence bedtime story about a unicorn.",
});
Console.WriteLine(response.OutputText);Execute dotnet run example.cs, and you'll see the API request output in a few seconds.
JAVA
To use the OpenAI API in Java, use the official OpenAI Java SDK.
Install SDK
Install the OpenAI SDK using Maven:
<dependency>
<groupId>com.openai</groupId>
<artifactId>openai-java</artifactId>
<version>1.0.0</version>
</dependency>After installing the OpenAI SDK, create a file named example.java and copy the example code into it:
import com.openai.OpenAIClient;
import com.openai.api.models.ResponseCreateRequest;
public class Example {
public static void main(String[] args) {
OpenAIClient client = new OpenAIClient("your_api_key_here", "https://api.agentsflare.com/v1");
ResponseCreateRequest request = new ResponseCreateRequest();
request.setModel("gpt-4.1");
request.setInput("Write a one-sentence bedtime story about a unicorn.");
var response = client.responses().create(request);
System.out.println(response.getOutputText());
}
}Execute java Example, and you'll see the API request output in a few seconds.
Go
go get github.com/openai/openai-goExample code(Chat Completion API request):
package main
import (
"context"
"fmt"
"log"
"os"
openai "github.com/openai/openai-go"
)
func main() {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
res, err := client.ChatCompletions.Create(context.Background(), openai.ChatCompletionCreateParams{
Model: openai.F("gpt-4.1"),
Messages: openai.ChatCompletionMessageParamsArray{
{
Role: openai.ChatCompletionMessageRoleUser,
Content: openai.F("Write a one-sentence bedtime story about a unicorn."),
},
},
})
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Choices[0].Message.Content)
}Execute go run example.go, and you'll see the API request output in a few seconds.
Other OpenAI Repositories
- tiktoken - Token counting (https://github.com/openai/tiktoken)
- simple-evals - Simple evaluation library (https://github.com/openai/simple-evals)
- mle-bench - Library for evaluating machine learning engineer agents (https://github.com/openai/mle-bench)
- gym - Reinforcement learning environments (https://github.com/openai/gym)
- swarm - Educational orchestration repository (https://github.com/openai/swarm)
Anthropic SDK Setup
Overview
Set up your development environment to call the Anthropic API using the SDK in your preferred language. This page covers how to set up your local development environment to use the Anthropic API. You can use officially supported SDKs or your favorite HTTP client.
Create and Export API Key
Before you begin, create an API key through the token instructions for secure API access. Store the key in a secure location, such as your .zshrc file or another text file on your computer. After generating the API key, export it as an environment variable in your terminal.
export ANTHROPIC_API_KEY="your_api_key_here"setx ANTHROPIC_API_KEY "your_api_key_here"$env:ANTHROPIC_API_KEY="your_api_key_here"Note: The Anthropic SDK automatically reads your API key from the system environment. You can also set the API key directly in your code, but this is not secure, especially when sharing code. It's recommended to use environment variables to protect your key.
Install Official SDK
JavaScript
To use the Anthropic API in server-side JavaScript environments (such as Node.js, Deno, or Bun), you can use the official TypeScript and JavaScript Anthropic SDK.
Install SDK
Install the Anthropic SDK using your preferred package manager. Here's an example command using npm:
npm install @anthropic-ai/sdkAfter installing the Anthropic SDK, create a file named anthropic-example.mjs and copy the example code into it:
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: process.env.ANTHROPIC_API_KEY,
baseURL: "https://api.agentsflare.com/anthropic/v1",
});
const response = await client.messages.create({
model: 'claude-3-5-sonnet-20241022',
max_tokens: 1024,
messages: [
{
role: 'user',
content: 'Write a one-sentence bedtime story about a unicorn.'
}
]
});
console.log(response.content[0].text);Execute with node anthropic-example.mjs (or equivalent command for Deno or Bun), and you'll see the API request output in a few seconds.
Python
To use the Anthropic API in Python, use the official Anthropic Python SDK.
Install SDK
Install the Anthropic SDK using pip:
pip install anthropicAfter installing the Anthropic SDK, create a file named anthropic-example.py and copy the example code into it:
import anthropic
import os
client = anthropic.Anthropic(
api_key=os.getenv("ANTHROPIC_API_KEY"),
base_url="https://api.agentsflare.com/anthropic/v1"
)
response = client.messages.create(
model="claude-3-5-sonnet-20241022",
max_tokens=1024,
messages=[
{
"role": "user",
"content": "Write a one-sentence bedtime story about a unicorn."
}
]
)
print(response.content[0].text)Execute python anthropic-example.py, and you'll see the API request output in a few seconds.
.NET
To use the Anthropic API in .NET, use the official Anthropic .NET SDK.
Install SDK
Install the Anthropic SDK using NuGet:
dotnet add package AnthropicAfter installing the Anthropic SDK, create a file named anthropic-example.cs and copy the example code into it:
using Anthropic;
using System;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
var client = new AnthropicClient(
Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY"),
new Uri("https://api.agentsflare.com/anthropic/v1")
);
var response = await client.Messages.CreateAsync(new MessageRequest
{
Model = "claude-3-5-sonnet-20241022",
MaxTokens = 1024,
Messages = new[]
{
new Message
{
Role = Role.User,
Content = "Write a one-sentence bedtime story about a unicorn."
}
}
});
Console.WriteLine(response.Content[0].Text);
}
}Execute dotnet run anthropic-example.cs, and you'll see the API request output in a few seconds.
Java
To use the Anthropic API in Java, use the official Anthropic Java SDK.
Install SDK
Install the Anthropic SDK using Maven:
<dependency>
<groupId>com.anthropic</groupId>
<artifactId>anthropic-java</artifactId>
<version>1.0.0</version>
</dependency>After installing the Anthropic SDK, create a file named anthropic-example.java and copy the example code into it:
import com.anthropic.client.AnthropicClient;
import com.anthropic.client.okhttp.AnthropicOkHttpClient;
import com.anthropic.models.Message;
import com.anthropic.models.MessageCreateParams;
import com.anthropic.models.Model;
AnthropicClient client = AnthropicOkHttpClient.fromEnv();
MessageCreateParams params = MessageCreateParams.builder()
.addUserMessage("Write a one-sentence bedtime story about a unicorn.")
.model(Model.CLAUDE_3_5_SONNET)
.maxTokens(1024)
.build();
Message message = client.messages().create(params);
System.out.println(message.getContent().get(0).getText());Execute java anthropic-example.java, and you'll see the API request output in a few seconds.
Go
To use the Anthropic API in Go, use the official Anthropic Go SDK.
Install SDK
Install the Anthropic SDK using Go Modules:
go get github.com/anthropics/anthropic-sdk-goAfter installing the Anthropic SDK, create a file named anthropic-example.go and copy the example code into it:
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/anthropics/anthropic-sdk-go"
)
func main() {
client := anthropic.NewClient(
anthropic.WithAPIKey(os.Getenv("ANTHROPIC_API_KEY")),
anthropic.WithBaseURL("https://api.agentsflare.com/anthropic/v1"),
)
response, err := client.Messages.New(context.Background(), anthropic.MessageNewParams{
Model: anthropic.F(anthropic.ModelClaude3_5Sonnet20241022),
MaxTokens: anthropic.F(int64(1024)),
Messages: anthropic.F([]anthropic.MessageParam{
anthropic.NewUserMessage(anthropic.NewTextBlock("Write a one-sentence bedtime story about a unicorn.")),
}),
})
if err != nil {
log.Fatalf("Messages.New error: %v", err)
}
fmt.Println(response.Content[0].Text)
}Execute go run anthropic-example.go, and you'll see the API request output in a few seconds.