go-openai

An unofficial Go client for the OpenAI API, covering Responses, Chat Completions, embeddings, images, audio, files, fine-tuning, batches, and vector stores.

SDK
Go
vv1.42.0
10,750stars
Apache License 2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
78/100Good
Development Activity64
Maintenance72
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
80/100Excellent
Architecture82
Code Quality85
Innovation62
Learning Curve90

go-openai is a community-maintained Go client for the OpenAI API. It wraps every major surface of the API — the newer Responses API for reasoning and multi-turn state, the long-standing Chat Completions endpoint, embeddings, image generation, audio transcription/translation/speech, moderation, file uploads, fine-tuning jobs, batches, vector stores, and the legacy Assistants API — behind a single typed Client.

The library is written entirely against the Go standard library, with zero third-party runtime dependencies, and supports Azure OpenAI and Anthropic-compatible endpoints alongside the default OpenAI base URL through a configurable ClientConfig. Streaming responses are modeled with Go generics over a shared SSE reader, giving each streaming endpoint (chat, responses, speech) a typed Recv() loop instead of raw byte handling.

With over 10,000 GitHub stars, 180+ contributors, and near-continuous releases tracking new OpenAI model and API launches, it is the de facto standard Go SDK for teams building on OpenAI without waiting on an official Go client.

What You Get

  • A single Client type (NewClient/NewClientWithConfig) that exposes every OpenAI API surface as typed Go methods instead of hand-rolled HTTP calls
  • Generics-based streaming (CreateChatCompletionStream, CreateResponseStream, CreateSpeechStream) with a typed Recv() loop over server-sent events
  • Built-in support for Azure OpenAI, Anthropic-compatible, and Cloudflare AI Gateway endpoints via APIType and DefaultAzureConfig, alongside the default OpenAI base URL
  • Structured error handling via errors.As(err, &openai.APIError{}), exposing HTTP status, error code, and message from failed API calls
  • A jsonschema sub-package for building tool/function-calling schemas without hand-writing JSON
  • Runnable examples for the Responses API, Chat Completions, function/tool calling, image generation, and speech-to-text under examples/

Common Use Cases

  • Backend AI integrations - Go services calling GPT models for chat, reasoning, or tool-augmented workflows via the Responses or Chat Completions APIs
  • Multi-turn assistants - applications that chain PreviousResponseID across calls to maintain conversation state without re-sending full history
  • Streaming UIs - CLI tools or backends that stream generated text token-by-token to a terminal or downstream client using the typed stream readers
  • Enterprise Azure deployments - teams running OpenAI models through Azure OpenAI Service who need deployment-aware URL construction and Azure API-key auth
  • Speech and transcription pipelines - Go services converting audio to text (Whisper) or text to speech using the audio API wrappers
  • Function/tool calling agents - Go programs that define callable tools with jsonschema and dispatch model tool-call requests to real functions

Under The Hood

Architecture go-openai centers on a single Client struct (client.go) holding a ClientConfig and two collaborators — a RequestBuilder and a FormBuilder (internal package) — that construct and serialize HTTP requests. Each API surface (chat.go, response.go, audio.go, image.go, embeddings.go, files.go, batch.go, vector_store.go, thread.go, run.go, assistant.go) is a thin method set on *Client that builds a request via newRequest, dispatches it through sendRequest/sendRequestStream, and decodes the typed response. Streaming reuses a single generic streamReader[T] (stream_reader.go) parameterized per endpoint, so chat, responses, and speech streaming share one SSE-parsing implementation rather than three. Azure and Anthropic-compatible routing is centralized in fullURL/baseURLWithAzureDeployment, keeping deployment-name and API-version logic out of individual endpoint methods. The design cleanly separates transport (internal/request_builder.go, internal/form_builder.go) from API surface (root package), so adding a new endpoint means adding a request/response pair and a method, not touching the transport layer.

Tech Stack The module (go 1.18 in go.mod) declares zero third-party runtime dependencies — everything is built on net/http, encoding/json, bufio, and context from the standard library, with Go generics used for the shared stream reader. Multipart form encoding for file/audio uploads is hand-implemented in internal/form_builder.go rather than delegated to a wrapper library. CI (.github/workflows/pr.yml, integration-tests.yml) runs unit tests plus opt-in integration tests against the live OpenAI API, and a close-inactive-issues workflow handles repo hygiene.

Code Quality The repository ships 34 _test.go files alongside their corresponding implementation files (one-to-one naming, e.g. chat.go/chat_test.go), covering both unit tests with mocked HTTP servers and integration tests gated behind a build tag. Errors are handled as typed values (APIError, RequestError) satisfying the standard error interface and inspectable via errors.As, rather than being swallowed or stringly-typed. Linting is enforced through an extensive .golangci.yml covering dozens of linters (errcheck, errorlint, exhaustive, funlen, gocognit, dupl, and more), and PRs run through CI before merge — a notably rigorous setup for a community-maintained SDK.

What Makes It Unique Unlike thinner community wrappers that only cover Chat Completions, go-openai tracks OpenAI’s full surface area — including the newer Responses API, vector stores, and the legacy Assistants API — while staying dependency-free and generics-based for streaming, which keeps the binary lean and avoids version-conflict risk in consuming projects. Its Azure/Anthropic-compatible endpoint abstraction lets the same client code target multiple deployment backends by swapping ClientConfig, which is unusual breadth for an unofficial SDK of this size.

Used by 7 apps in this directory

Go
60%
Apache 2.0

Apache Answer

Community

15,658

Open-source Q&A platform for communities, help centers, and knowledge bases with AI assistant and plugin extensibility

View details
84
Repo Health
78
Technical
68
Dependency
Built with
Go60%
TypeScript36%
Updated 2 days ago
Go
82%
AGPL 3.0

Beta9

Developer Tools · AI Development · Data Engineering

1,762

Run AI workloads at scale with a Pythonic serverless runtime that handles GPU inference, background jobs, and sandboxes with zero infrastructure overhead.

View details
84
Repo Health
78
Technical
67
Dependency
Built with
Go82%
Python17%
Updated 3 days ago
Go
92%
AGPL 3.0

BillionMail

Marketing

15,489

Self-hosted email server and marketing platform that gives you unlimited sending, full deliverability control, and AI-assisted campaigns without monthly fees.

View details
58
Repo Health
74
Technical
72
Dependency
Built with
Go92%
Updated 2 months ago
Go
84%
MIT

Hatchet

AI Development · Developer Tools · Automation

7,812

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
68
Dependency
Built with
Go84%
PLpgSQL11%
Updated today
TypeScript
71%
Other

highlight.io

Developer Tools · Analytics · Monitoring

9,373

Open-source full-stack monitoring that unifies session replay, error tracking, logging, and distributed tracing so you can stop context-switching between tools.

View details
70
Repo Health
78
Technical
65
Dependency
Built with
TypeScript71%
Go16%
Updated 1 weeks ago
Go
93%
MIT

Plandex

AI Code Assistants

15,598

An open-source, terminal-based AI coding agent built for large tasks and real codebases — with its own version control for plans, a 2M-token effective context window, and self-hosted or cloud deployment.

View details
49
Repo Health
70
Technical
68
Dependency
Built with
Go93%
Updated 11 months ago
TypeScript
97%
MIT

Promptfoo

AI Development

24,672

An open-source CLI and library for evaluating and red-teaming LLM applications — replace trial-and-error prompt engineering with systematic evals, vulnerability scanning, and CI/CD integration.

View details
90
Repo Health
73
Technical
68
Dependency
Built with
TypeScript97%
Updated today

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

Search