Repolode
sashabaranov

sashabaranov/go-openai

An unofficial, zero-dependency Go client for the OpenAI API, covering Responses, Chat Completions, images, audio and more.

Stars
10,807
Forks
1,714
Open issues
226
Last commit
last month

What is it?

go-openai is an unofficial Go client library for the OpenAI API. It lets Go programs call OpenAI services such as the Responses API, Chat Completions, embeddings, image generation, speech-to-text, moderation, files, fine-tuning, batches and vector stores through typed request and response structs.

The library supports streaming responses, customizable HTTP clients and base URLs, and Azure OpenAI configuration. Errors returned by the API can be inspected with errors.As through the APIError type. Model constants are provided for current OpenAI models, and model IDs can be passed as plain strings for models not yet defined in the package.

The Responses API is the recommended starting point for new text-generation and tool-calling integrations, while Chat Completions remains available for existing code. The project includes runnable examples for multi-turn responses, function tools, image generation and voice-to-text.

Key features

  • 01Typed Go structs for Responses, Chat Completions, images, audio and other OpenAI endpoints.
  • 02Streaming support for both Responses and Chat Completions.
  • 03Configurable HTTP client, base URL, organization and headers.
  • 04Azure OpenAI configuration helper.
  • 05Structured API errors that work with errors.As.

Use cases

  • Adding OpenAI-powered text generation or tool calling to a Go backend service.
  • Building streaming chat interfaces that display model output as it arrives.
  • Generating images or transcribing audio from Go applications.
  • Pointing a Go client at OpenAI-compatible endpoints via a custom base URL.

Quick start

  1. 1

    Install the library with go get

    go get github.com/sashabaranov/go-openai
  2. 2

    Set your OpenAI API key in the environment

    export OPENAI_API_KEY="<your key>"
  3. 3

    Run the Responses API example from the examples directory

    go run ./examples/responses

Things to know

  • This is an unofficial client, not maintained by OpenAI.
  • Requires Go 1.18 or later and an OpenAI API key.

In collections

Topics

FAQ

What is go-openai?
An unofficial, zero-dependency Go client for the OpenAI API, covering Responses, Chat Completions, images, audio and more. go-openai is an unofficial Go client library for the OpenAI API. It lets Go programs call OpenAI services such as the Responses API, Chat Completions, embeddings, image generation, speech-to-text, moderation, files, fine-tuning, batches and vector stores through typed request and response structs.
Is go-openai free to use? What license does it have?
go-openai is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is go-openai still maintained?
Updated within 6 months. The last commit to go-openai was on Sep 29, 2026.
What can I use go-openai for?
Adding OpenAI-powered text generation or tool calling to a Go backend service. Building streaming chat interfaces that display model output as it arrives. Generating images or transcribing audio from Go applications. Pointing a Go client at OpenAI-compatible endpoints via a custom base URL.
How do I install go-openai?
Install the library with go get: go get github.com/sashabaranov/go-openai Set your OpenAI API key in the environment: export OPENAI_API_KEY="<your key>" Run the Responses API example from the examples directory: go run ./examples/responses
Where can I get go-openai?
The source code and installation instructions are on GitHub: https://github.com/sashabaranov/go-openai

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects