gitmyhub

go-openai

Go ★ 11k updated 8mo ago

OpenAI ChatGPT, GPT-5, GPT-Image-1, Whisper API clients for Go

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.

Gosetup: easycomplexity 2/5

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.

Where it fits