explaingit

sashabaranov/go-openai

10,657GoAudience · developerComplexity · 2/5Setup · easy

TLDR

A Go library that handles all the details of calling OpenAI's APIs, chat, image generation, speech-to-text, and embeddings, so you can add AI features to a Go program without writing the HTTP plumbing yourself.

Mindmap

mindmap
  root((go-openai))
    What it does
      OpenAI API client
      Go language library
      Community unofficial
    Capabilities
      Chat and streaming
      Image generation
      Speech to text
      Embeddings
    Use Cases
      AI chat in Go apps
      Image from text
      Audio transcription
    Setup
      Go 1.18 required
      API key needed
      Works with alt APIs
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Add streaming AI chat responses to a Go application using OpenAI GPT models

USE CASE 2

Generate images from text prompts in a Go program using DALL-E or GPT Image

USE CASE 3

Transcribe or translate audio files in Go using the Whisper speech-to-text API

USE CASE 4

Create text embeddings in Go for use in search or similarity features

Tech stack

Go

Getting it running

Difficulty · easy Time to first run · 30min

Requires a paid OpenAI API key to call the API.

In plain English

Go-openai is a Go library that makes it straightforward to call OpenAI's APIs from a Go program. OpenAI provides services like ChatGPT for text generation, Whisper for converting speech to text, and DALL-E and GPT Image for generating images from text descriptions. These services are accessible over the internet through an API, meaning a program sends a request and gets a response back. This library handles the details of formatting those requests and parsing the responses, so developers do not have to write that plumbing themselves. The core use case is sending chat messages to a language model and receiving a reply. The library supports both regular request-and-response calls and streaming, where the reply arrives word by word as it is generated, similar to how ChatGPT types out its answers on screen. Both styles are common: streaming is better for showing output to a user in real time, while the standard call is simpler when the result is processed further before being shown. Beyond chat, the library covers several other OpenAI capabilities: generating images from a text prompt using DALL-E 2, DALL-E 3, or the newer GPT Image 1 model, transcribing or translating audio files using the Whisper model, creating text embeddings, which are numerical representations of text used in search and similarity tasks, and fine-tuning models on custom data. The README includes working code examples for most of these. The library requires Go 1.18 or later. It is unofficial, meaning it is a community project not produced or endorsed by OpenAI, though it covers the official OpenAI API surface. Configuration options allow pointing it at compatible alternative APIs, such as self-hosted models that speak the same protocol.

Copy-paste prompts

Prompt 1
Using go-openai, help me write a Go function that sends a user message to GPT-4 and streams the reply token by token to standard output.
Prompt 2
Show me how to use go-openai to transcribe an MP3 file using the Whisper model and print the resulting text in Go.
Prompt 3
Help me configure go-openai to point at a local self-hosted model that uses the OpenAI-compatible API format.
Prompt 4
I want to generate an image from a text prompt using DALL-E 3 in Go, show me the complete go-openai code to do that.
Prompt 5
Help me create text embeddings for a list of strings using go-openai so I can compare their similarity scores.
Open on GitHub → Explain another repo

← sashabaranov on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.