Skip to content

Providers and Models

A provider is an AI service (OpenAI, Anthropic, Google, etc.). A model is a specific model offered by that provider (gpt-4o, claude-sonnet-4-20250514, gemini-2.0-flash).

GoAI uses a factory pattern: each provider package exports a Chat() function that returns a model implementing the provider.LanguageModel interface.

go
import "github.com/zendev-sh/goai/provider/openai"

model := openai.Chat("gpt-4o")

The model is then passed to GoAI functions like StreamText or GenerateText:

go
result, err := goai.GenerateText(ctx, model,
    goai.WithPrompt("Explain quantum computing in one sentence."),
)

Model Interfaces

GoAI defines three model interfaces in the provider package.

LanguageModel

Text generation and tool calling.

go
type LanguageModel interface {
    ModelID() string
    DoGenerate(ctx context.Context, params GenerateParams) (*GenerateResult, error)
    DoStream(ctx context.Context, params GenerateParams) (*StreamResult, error)
    Capabilities() ModelCapabilities
}

Used with GenerateText, StreamText, GenerateObject, and StreamObject.

EmbeddingModel

Vector embeddings from text.

go
type EmbeddingModel interface {
    ModelID() string
    DoEmbed(ctx context.Context, values []string, params EmbedParams) (*EmbedResult, error)
    MaxValuesPerCall() int
}

Used with Embed and EmbedMany.

ImageModel

Image generation from text prompts.

go
type ImageModel interface {
    ModelID() string
    DoGenerate(ctx context.Context, params ImageParams) (*ImageResult, error)
}

Used with GenerateImage.

Capabilities

Every LanguageModel exposes a Capabilities() method that describes what the model supports:

go
caps := model.Capabilities()
if caps.ToolCall {
    // safe to pass tools
}
if caps.Reasoning {
    // model supports extended thinking
}

The ModelCapabilities struct includes:

FieldTypeDescription
TemperatureboolAccepts temperature parameter
ReasoningboolExtended thinking / chain-of-thought
AttachmentboolFile attachment support
ToolCallboolTool / function calling
InputModalitiesModalitySetSupported input types (text, image, etc.)
OutputModalitiesModalitySetSupported output types

Provider Configuration

Every provider accepts options for authentication and customization:

go
// Explicit API key
model := openai.Chat("gpt-4o", openai.WithAPIKey("sk-..."))

// Dynamic token source (OAuth, service accounts)
model := openai.Chat("gpt-4o", openai.WithTokenSource(myTokenSource))

// Custom HTTP client (proxies, logging, URL rewrite)
model := openai.Chat("gpt-4o", openai.WithHTTPClient(myClient))

If no API key or token source is provided, providers read from environment variables (e.g., OPENAI_API_KEY, ANTHROPIC_API_KEY).

Provider List

ProviderImport PathFactory Functions
OpenAIgithub.com/zendev-sh/goai/provider/openaiChat, Embedding, Image
Anthropicgithub.com/zendev-sh/goai/provider/anthropicChat
Googlegithub.com/zendev-sh/goai/provider/googleChat, Embedding, Image
Azuregithub.com/zendev-sh/goai/provider/azureChat, Image
Vertex AIgithub.com/zendev-sh/goai/provider/vertexChat, Embedding, Image
Bedrockgithub.com/zendev-sh/goai/provider/bedrockChat
Mistralgithub.com/zendev-sh/goai/provider/mistralChat
xAIgithub.com/zendev-sh/goai/provider/xaiChat
Groqgithub.com/zendev-sh/goai/provider/groqChat
DeepInfragithub.com/zendev-sh/goai/provider/deepinfraChat
OpenRoutergithub.com/zendev-sh/goai/provider/openrouterChat
DeepSeekgithub.com/zendev-sh/goai/provider/deepseekChat
Fireworksgithub.com/zendev-sh/goai/provider/fireworksChat
Togethergithub.com/zendev-sh/goai/provider/togetherChat
Coheregithub.com/zendev-sh/goai/provider/cohereChat, Embedding
Cerebrasgithub.com/zendev-sh/goai/provider/cerebrasChat
Perplexitygithub.com/zendev-sh/goai/provider/perplexityChat
Ollamagithub.com/zendev-sh/goai/provider/ollamaChat, Embedding
vLLMgithub.com/zendev-sh/goai/provider/vllmChat, Embedding
Compatgithub.com/zendev-sh/goai/provider/compatChat, Embedding

The compat provider works with any OpenAI-compatible API. Pass a custom base URL:

go
import "github.com/zendev-sh/goai/provider/compat"

model := compat.Chat("my-model",
    compat.WithBaseURL("https://my-api.example.com/v1"),
    compat.WithAPIKey("my-key"),
)

Released under the MIT License.