openai/openai-go
The official Go library for the OpenAI API
What it solves
This library provides a convenient, type-safe way for developers to interact with the OpenAI REST API using the Go programming language, eliminating the need to manually construct HTTP requests and handle raw JSON responses.
How it works
It acts as a Go SDK that wraps the OpenAI REST API. It uses a functional options pattern for configuration and provides structured request and response objects. Key features include:
- Responses API: The primary interface for generating text and interacting with models.
- Conversations: Support for multi-turn interactions and conversation state management.
- Streaming: Ability to stream responses in real-time.
- Tool Calling: Integration with external functions to allow models to perform actions.
- Structured Outputs: Support for JSON schema-based outputs to ensure the model returns data in a specific format.
- Pagination: Built-in helpers for iterating through paginated list endpoints.
Who it’s for
Go developers who want to integrate OpenAI's models and capabilities into their applications.
Highlights
- Type Safety: Uses Go's type system to ensure request parameters and response fields are correctly handled.
- Structured Outputs: Direct support for JSON schema to ensure predictable model responses.
- Advanced API Support: Includes full support for the Responses API, Chat Completions, and tool calling.
- Flexible Configuration: Functional options allow for easy header and timeout customization.
- Robust Error Handling: Provides a specific
openai.Errortype for detailed API error diagnostics.
Related
- Project
- Project
- Project
- Project
- Project