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)
}

Used with GenerateText, StreamText, GenerateObject, and StreamObject.

Models may also implement the optional CapableModel interface to declare capabilities. Use provider.ModelCapabilitiesOf(model) to query safely.

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

Models that implement the optional CapableModel interface expose their capabilities. Use provider.ModelCapabilitiesOf to query safely (returns zero-value if not implemented):

go
caps := provider.ModelCapabilitiesOf(model)
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

Providers expose authentication and customization options, but option names vary by provider:

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))

Many providers read credentials from environment variables when explicit auth options are omitted (for example OPENAI_API_KEY, ANTHROPIC_API_KEY). Some providers use provider-specific auth options (for example Bedrock uses AWS credential options instead of WithAPIKey/WithTokenSource).

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, Embedding
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
MiniMaxgithub.com/zendev-sh/goai/provider/minimaxChat
RunPodgithub.com/zendev-sh/goai/provider/runpodChat
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.