go-openai
OpenAI, GPT 6.1, GPT-Image-2, Whisper API clients for Go. Zero-dependency.
What is go-openai?
OpenAI, GPT 6.1, GPT-Image-2, Whisper API clients for Go. Zero-dependency.
Overview of go-openai
What it is
An unofficial Go client for the OpenAI API. It supports the Responses API for new text-generation, reasoning, tool-calling, and multi-turn integrations, while Chat Completions remains available for existing integrations. The client also covers embeddings, images, audio, moderation, files, fine-tuning, batches, vector stores, and legacy Assistants API surfaces. It requires Go 1.18 or later and has zero dependencies.
Key features
- Zero-dependency Go client for OpenAI API
- Supports Responses API (new) and Chat Completions (legacy)
- Covers embeddings, images, audio, moderation, files, fine-tuning, batches, vector stores, and Assistants API
- Streaming output support
- Configurable HTTP client, base URL, organization, and headers
- Azure OpenAI support via
DefaultAzureConfig - Error handling with typed
APIError - Runnable examples in
examples/directory
Use cases
- Building agents and multi-turn conversational applications
- Text generation with reasoning and tool calling
- Image generation and speech-to-text
- Integrating with OpenAI's latest models (GPT-6.1 Sol, GPT-6 Astra, etc.)
- Customizing API endpoints for compatible services
Getting started
Install the package:
go get github.com/sashabaranov/go-openai
Set your OpenAI API key:
export OPENAI_API_KEY=""
Create a response (Responses API example):
package main
import (
"context"
"fmt"
"log"
"os"
openai "github.com/sashabaranov/go-openai"
)
func main() {
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
response, err := client.CreateResponse(context.Background(), openai.CreateResponseRequest{
Model: openai.GPT5Dot6Sol,
Instructions: "You are a concise technical explainer.",
Input: "Why is the sky blue?",
})
if err != nil {
log.Fatal(err)
}
fmt.Println(response.GetOutputText())
}
For more examples, see the examples/ directory.
License and pricing
Licensed under Apache-2.0. The package is open source and free to use.
Based on the project's public README and repository metadata.