OpenAI Go

The official Go library for the OpenAI API, covering Responses, Chat Completions, Realtime, Assistants, and more with generated, type-safe bindings.

SDK
Go
vv3.86.0
3,505 stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
89 /100 Excellent
Development Activity 100
Maintenance 100
Community 68
Maturity 48
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
84 /100 Excellent
Architecture 85
Code Quality 92
Innovation 78
Learning Curve 80

openai-go is OpenAI’s officially maintained Go client, generated directly from OpenAI’s OpenAPI specification by Stainless (branded internally as Castiron). It gives Go applications typed access to the full surface of the OpenAI platform: the Responses API, the legacy-but-still-supported Chat Completions API, Realtime, Assistants (beta), Conversations, Embeddings, Fine-tuning, Batches, Vector Stores, Moderations, Files/Uploads, Images, Audio, Webhooks, and Admin endpoints.

The library leans on Go 1.24+ encoding/json omitzero semantics to distinguish “not set” from a real zero value in request params, using param.Opt[T] wrappers and generated union types (e.g. ResponseNewParamsInputUnion) instead of loosely-typed interface{} payloads. It ships first-class support for the Amazon Bedrock and Azure OpenAI-compatible endpoints, workload-identity (mTLS/X.509) authentication, and webhook signature verification via client.Webhooks.Unwrap().

Because the package lives at major version 3, its Go module path is versioned as github.com/openai/openai-go/v3 per Go modules convention; SDK v3.45.0+ requires Go 1.25, with v3.44.0 pinned as the last release supporting Go 1.22-1.24.

What You Get

  • A generated Client with one service field per API resource (client.Responses, client.Chat.Completions, client.Embeddings, client.FineTuning, client.VectorStores, client.Batches, client.Admin, client.Realtime, client.Conversations, client.Webhooks, etc.)
  • Type-safe request params using param.Opt[T] for optional fields and generated union types for polymorphic inputs (e.g. string vs. structured input to the Responses API)
  • Built-in streaming support (client.Responses.NewStreaming, chat completion streaming) with a stream accumulator for reconstructing full responses from deltas
  • Webhook signature verification (client.Webhooks.Unwrap()) that parses and authenticates OpenAI webhook payloads in one call
  • Native support for Amazon Bedrock and Azure OpenAI in Azure AI Foundry as alternate backends, plus workload-identity (mTLS/X.509) authentication for enterprise deployments
  • Automatic environment-variable configuration (OPENAI_API_KEY, OPENAI_ADMIN_KEY, OPENAI_ORG_ID, OPENAI_PROJECT_ID, OPENAI_WEBHOOK_SECRET, OPENAI_BASE_URL) via option.RequestOptions

Common Use Cases

  • Generating text or structured JSON output from GPT models via the Responses API in a Go backend service
  • Building a streaming chat interface that consumes token-by-token deltas from Responses.NewStreaming or Chat.Completions.NewStreaming
  • Implementing tool/function calling where the model requests external data and the Go app resolves it and continues the conversation
  • Receiving and verifying OpenAI webhook events (e.g. fine-tuning job completion) in an HTTP handler with client.Webhooks.Unwrap()
  • Routing OpenAI-compatible requests through Amazon Bedrock or Azure OpenAI instead of OpenAI’s own endpoint for compliance or data-residency reasons

Under The Hood

Architecture

The root Client struct in client.go composes one service field per API resource (Responses, Chat, Embeddings, FineTuning, VectorStores, Batches, Webhooks, Realtime, Conversations, Admin, and more), each backed by its own generated file or subpackage (responses/, realtime/, conversations/, webhooks/, bedrock/, azure/, auth/). Requests flow through a shared internal/requestconfig layer and an option.RequestOption pipeline that composes API key, organization, project, base URL, and retry/middleware behavior before dispatch. Backend selection (direct OpenAI, Amazon Bedrock, or Azure OpenAI in Azure AI Foundry) is handled by swapping in the bedrock or azure subpackage’s client options rather than branching application code, keeping the resource-service API identical across backends. Streaming responses are handled by a dedicated stream/accumulator layer (streamaccumulator*.go) that reconstructs a complete response object from server-sent-event deltas.

Tech Stack

The module (github.com/openai/openai-go/v3, Go 1.25+) has a deliberately small direct dependency set for a client this large: github.com/tidwall/gjson/sjson for JSON path manipulation, plus Azure/azure-sdk-for-go and aws-sdk-go-v2 subpackages pulled in only for the optional Azure and Bedrock backends. Requests use Go 1.24+ encoding/json omitzero semantics via param.Opt[T] wrappers rather than a third-party validation library. CI (.github/workflows/ci.yml, codeql.yml, go-version-review.yml) runs standard go build/go test/CodeQL, plus custom detect-breaking-changes.yml and Castiron-branded code-generation checks that gate manually-edited generated code.

Code Quality

The repo carries 113 _test.go files alongside their corresponding generated source files (one test per resource, e.g. chatcompletion_test.go, responses package tests, streamaccumulator_*_test.go covering lifetime, ownership, reconciliation, and logprob edge cases). Errors are returned as explicit Go error values rather than panics in library code (the README’s own examples panic() only for brevity). Naming is consistent and mechanically generated (resource+action, e.g. adminorganizationprojectuser.go), and a .golangci.yml plus documented GO_CODE_QUALITY_POLICY.md/GO_VERSION_POLICY.md formalize lint rules and the supported Go version window.

What Makes It Unique

Unlike many hand-written API clients, this SDK is generated end-to-end from OpenAI’s OpenAPI spec (via the Castiron/Stainless pipeline referenced in file headers and CONTRIBUTING.md), so new API surface area ships automatically rather than through manual client updates. It also uniquely unifies three backends (OpenAI direct, Amazon Bedrock, Azure OpenAI in Azure AI Foundry) and adds enterprise-grade workload-identity (mTLS/X.509) authentication and strict webhook-signature verification with a documented 1 MiB payload-size defense-in-depth recommendation, both unusual for a generated client library.

Used by 11 apps in this directory

Rust
44%
MIT

Anarlog

AI Assistants · Note Taking · Productivity

9,565

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
65
Dependency
Built with
Rust 44%
TypeScript 41%
Updated 5 days ago
Go
75%
AGPL 3.0

Coder

Code Editors · Developer Tools · Devops

17,157

Self-hosted cloud development environments and AI coding agents — defined in Terraform, connected via WireGuard, automatically shut down when idle.

View details
91
Repo Health
90
Technical
66
Dependency
Built with
Go 75%
TypeScript 23%
Updated 5 days ago
Go
99%
Other

Crush

AI Assistants · AI Code Assistants · Developer Tools

28,781

Your terminal coding companion — wire up any LLM with LSP intelligence, MCP extensibility, and a skills system that learns your workflow.

View details
87
Repo Health
86
Technical
68
Dependency
Built with
Go 99%
Updated 5 days ago
TypeScript
47%
AGPL 3.0

Grafana

Analytics · Monitoring

77,469

The open-source observability platform that unifies metrics, logs, and traces from any data source into dynamic, queryable dashboards.

View details
95
Repo Health
91
Technical
63
Dependency
Built with
TypeScript 47%
Go 47%
Updated 5 days ago
Go
53%
MIT

memos

Note Taking

64,031

Open-source, self-hosted note-taking built for quick capture — Markdown-native, lightweight, and fully yours.

View details
91
Repo Health
78
Technical
65
Dependency
Built with
Go 53%
TypeScript 46%
Updated 5 days ago
Go
56%
Other

Multica

AI Assistants · AI Development

53,682

Turn coding agents into real teammates — assign issues, track progress, and compound reusable skills across a vendor-neutral, self-hosted platform.

View details
87
Repo Health
83
Technical
67
Dependency
Built with
Go 56%
TypeScript 38%
Updated 5 days ago
Go
75%
Other

Notifuse

Marketing

2,256

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
83
Repo Health
80
Technical
65
Dependency
Built with
Go 75%
TypeScript 22%
Updated 6 days ago
Go
69%
Apache 2.0

open-code-review

Developer Tools · Devops

48,167

The AI code review agent born at Alibaba's scale — combining deterministic engineering with LLM intelligence for precise, token-efficient reviews.

View details
82
Repo Health
83
Technical
73
Dependency
Built with
Go 69%
JavaScript 12%
Updated 1 weeks ago
Go
40%
Apache 2.0

Rill

Analytics · Data Engineering

2,962

The fastest BI tool for humans and agents — define metrics, models, and dashboards as code and query them instantly on ClickHouse or DuckDB.

View details
88
Repo Health
88
Technical
64
Dependency
Built with
Go 40%
TypeScript 38%
Svelte 21%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers