openai-go  by openai

Go SDK for OpenAI API

created 1 year ago
2,117 stars

Top 21.7% on sourcepulse

GitHubView on GitHub
Project Summary

This Go library provides a convenient interface to the OpenAI REST API, targeting Go developers building applications that leverage AI models for tasks like text generation, chat, and structured data extraction. It offers a type-safe, idiomatic Go experience for interacting with OpenAI's powerful AI capabilities.

How It Works

The library maps OpenAI API endpoints to Go functions and structs, utilizing Go's type system for request and response handling. It employs the functional options pattern for configuring requests (e.g., API keys, timeouts, retries) and provides robust support for advanced features like streaming responses, tool calling, and structured output generation via JSON schema. The design emphasizes clarity and safety, with explicit handling for optional parameters and detailed error reporting.

Quick Start & Requirements

  • Install: go get -u github.com/openai/openai-go
  • Requirements: Go 1.18+
  • Usage: See the API documentation and provided examples.

Highlighted Details

  • Supports chat completions, streaming responses, tool calling, and structured outputs.
  • Implements omitzero semantics for request fields and provides helpers for optional parameters (param.Opt[T]).
  • Offers automatic retries for transient errors and configurable timeouts via context.
  • Includes utilities for paginating list endpoints and accessing raw response data.

Maintenance & Community

Licensing & Compatibility

  • License: MIT
  • Compatible with commercial and closed-source applications.

Limitations & Caveats

The library notes that the latest version has significant breaking changes, requiring migration. Some features, like structured outputs, are model-specific.

Health Check
Last commit

3 days ago

Responsiveness

1 day

Pull Requests (30d)
17
Issues (30d)
20
Star History
428 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.