# Providers and Models

Companies such as OpenAI and Anthropic (providers) offer access to a range of large language models (LLMs) with differing strengths and capabilities through their own APIs.

Each provider typically has its own unique method for interfacing with their models, complicating the process of switching providers and increasing the risk of vendor lock-in.

To solve these challenges, the Go AI SDK offers a standardized approach to interacting with LLMs through a unified provider interface that abstracts differences between providers. This unified interface allows you to switch between providers with ease while using the same API for all providers.

## Unified Provider Architecture

The Go AI SDK uses a consistent provider architecture where all providers implement the same interfaces:

```go
// All providers implement these interfaces
type Provider interface {
    LanguageModel(modelID string) (LanguageModel, error)
    EmbeddingModel(modelID string) (EmbeddingModel, error)
    ImageModel(modelID string) (ImageModel, error)
    SpeechModel(modelID string) (SpeechModel, error)
    TranscriptionModel(modelID string) (TranscriptionModel, error)
    RerankingModel(modelID string) (RerankingModel, error)
}
```

This means switching providers is as simple as changing which provider you instantiate:

```go
// OpenAI
openaiProvider := openai.New(openai.Config{APIKey: os.Getenv("OPENAI_API_KEY")})
model1, _ := openaiProvider.LanguageModel("gpt-4")

// Anthropic
anthropicProvider := anthropic.New(anthropic.Config{APIKey: os.Getenv("ANTHROPIC_API_KEY")})
model2, _ := anthropicProvider.LanguageModel("claude-3-5-sonnet-20241022")

// Same API for both
result1, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{Model: model1, Prompt: "Hello"})
result2, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{Model: model2, Prompt: "Hello"})
```

## Supported Providers

The Go AI SDK includes built-in support for 26+ providers:

### Language Model Providers

- **[OpenAI](https://goaisdk.com/docs/providers/openai.md)** - GPT-4, GPT-3.5, o1 series
  ```go

  ```

- **[Anthropic](https://goaisdk.com/docs/providers/anthropic.md)** - Claude 3 (Opus, Sonnet, Haiku), Claude 4
  ```go

  ```

- **[Google](https://goaisdk.com/docs/providers/google.md)** - Gemini Pro, Gemini Flash
  ```go

  ```

- **[Azure OpenAI](https://goaisdk.com/docs/providers/azure.md)** - All Azure-hosted models
  ```go

  ```

- **[Amazon Bedrock](https://goaisdk.com/docs/providers/bedrock.md)** - Claude, Titan, Llama, and more
  ```go

  ```

- **[Cohere](https://goaisdk.com/docs/providers/cohere.md)** - Command, Command-R series
  ```go

  ```

- **[Mistral](https://goaisdk.com/docs/providers/mistral.md)** - Mistral Large, Medium, Small
  ```go

  ```

- **[Groq](https://goaisdk.com/docs/providers/groq.md)** - Fast inference with Llama, Mixtral
  ```go

  ```

- **[DeepSeek](https://goaisdk.com/docs/providers/deepseek.md)** - DeepSeek Chat, Coder
  ```go

  ```

- **[xAI](https://goaisdk.com/docs/providers/xai.md)** - Grok models
  ```go

  ```

- **[Perplexity](https://goaisdk.com/docs/providers/perplexity.md)** - Sonar models
  ```go

  ```

- **[Together AI](https://goaisdk.com/docs/providers/together.md)** - Llama, Mixtral, Qwen
  ```go

  ```

- **[Fireworks](https://goaisdk.com/docs/providers/fireworks.md)** - Fast inference for various models
  ```go

  ```

- **[Replicate](https://goaisdk.com/docs/providers/replicate.md)** - All hosted models
  ```go

  ```

- **[Hugging Face](https://goaisdk.com/docs/providers/huggingface.md)** - Router Responses API models
  ```go

  ```

- **[Ollama](https://goaisdk.com/docs/providers/ollama.md)** - Local models
  ```go

  ```

### Image Generation Providers

- **[Stability AI](https://goaisdk.com/docs/providers/stability.md)** - Stable Diffusion
  ```go

  ```

- **[Black Forest Labs](https://goaisdk.com/docs/providers/bfl.md)** - FLUX models
  ```go

  ```

- **[Fal.ai](https://goaisdk.com/docs/providers/fal.md)** - Fast image generation
  ```go

  ```

### Speech & Transcription Providers

- **[ElevenLabs](https://goaisdk.com/docs/providers/elevenlabs.md)** - Text-to-speech
  ```go

  ```

- **[Deepgram](https://goaisdk.com/docs/providers/deepgram.md)** - Speech-to-text
  ```go

  ```

- **[AssemblyAI](https://goaisdk.com/docs/providers/assemblyai.md)** - Speech recognition
  ```go

  ```

### Infrastructure Providers

- **[Baseten](https://goaisdk.com/docs/providers/baseten.md)** - Model serving infrastructure
  ```go

  ```

- **[Cerebras](https://goaisdk.com/docs/providers/cerebras.md)** - Fast inference hardware
  ```go

  ```

- **[DeepInfra](https://goaisdk.com/docs/providers/deepinfra.md)** - Multi-model inference
  ```go

  ```

- **[Vercel AI](https://goaisdk.com/docs/providers/vercel.md)** - Vercel's hosted models
  ```go

  ```

## Self-Hosted Models

You can run models locally with:

- **Ollama** - Run Llama, Mistral, and other models locally
- **LM Studio** (via OpenAI-compatible interface)
- Any OpenAI-compatible server

Example with Ollama:

```go
import "github.com/digitallysavvy/go-ai/pkg/providers/ollama"

provider := ollama.New(ollama.Config{
    BaseURL: "http://localhost:11434",
})

model, _ := provider.LanguageModel("llama2")

result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
    Model:  model,
    Prompt: "Hello from my local machine!",
})
```

## Model Capabilities

Different models support different capabilities. You can check what a model supports:

```go
model, _ := provider.LanguageModel("gpt-4")

// Check capabilities
if model.SupportsTools() {
    fmt.Println("Model supports tool calling")
}

if model.SupportsStructuredOutput() {
    fmt.Println("Model supports structured output")
}

if model.SupportsImageInput() {
    fmt.Println("Model can process images")
}
```

### Capability Matrix

Here are the capabilities of popular models:

| Provider | Model | Image Input | Structured Output | Tool Calling | Tool Streaming |
|----------|-------|-------------|-------------------|--------------|----------------|
| OpenAI | gpt-4 | ✓ | ✓ | ✓ | ✓ |
| OpenAI | gpt-4-turbo | ✓ | ✓ | ✓ | ✓ |
| OpenAI | gpt-3.5-turbo | ✗ | ✓ | ✓ | ✓ |
| Anthropic | claude-opus-4 | ✓ | ✓ | ✓ | ✓ |
| Anthropic | claude-sonnet-4 | ✓ | ✓ | ✓ | ✓ |
| Anthropic | claude-3.5-haiku | ✓ | ✓ | ✓ | ✓ |
| Google | gemini-2.0-flash | ✓ | ✓ | ✓ | ✓ |
| Google | gemini-1.5-pro | ✓ | ✓ | ✓ | ✓ |
| Mistral | pixtral-large | ✓ | ✓ | ✓ | ✓ |
| Mistral | mistral-large | ✗ | ✓ | ✓ | ✓ |
| DeepSeek | deepseek-chat | ✗ | ✓ | ✓ | ✓ |
| Groq | llama-3.3-70b | ✗ | ✓ | ✓ | ✓ |

> **Note:** This table is not exhaustive. Additional models and their capabilities can be found in the individual provider documentation pages.

## Using Multiple Providers

One advantage of the unified interface is that you can easily use multiple providers in the same application:

```go
package main

import (
    "context"
    "fmt"
    "os"

    "github.com/digitallysavvy/go-ai/pkg/ai"
    "github.com/digitallysavvy/go-ai/pkg/providers/openai"
    "github.com/digitallysavvy/go-ai/pkg/providers/anthropic"
)

func main() {
    ctx := context.Background()

    // Use GPT-4 for initial response
    openaiProvider := openai.New(openai.Config{APIKey: os.Getenv("OPENAI_API_KEY")})
    gpt4, _ := openaiProvider.LanguageModel("gpt-4")

    result1, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
        Model:  gpt4,
        Prompt: "Generate a creative story idea",
    })

    // Use Claude for critique
    anthropicProvider := anthropic.New(anthropic.Config{APIKey: os.Getenv("ANTHROPIC_API_KEY")})
    claude, _ := anthropicProvider.LanguageModel("claude-3-5-sonnet-20241022")

    result2, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
        Model:  claude,
        Prompt: fmt.Sprintf("Critique this story idea: %s", result1.Text),
    })

    fmt.Println("Story Idea:", result1.Text)
    fmt.Println("Critique:", result2.Text)
}
```

## Provider Registry

For applications that need dynamic provider/model selection, use the registry:

```go
import "github.com/digitallysavvy/go-ai/pkg/registry"

// Create registry and register providers
reg := registry.NewRegistry()
reg.RegisterProvider("openai", openaiProvider)
reg.RegisterProvider("anthropic", anthropicProvider)
reg.RegisterProvider("google", googleProvider)

// Resolve models by string ID
model, _ := reg.ResolveLanguageModel("openai:gpt-4")
model2, _ := reg.ResolveLanguageModel("anthropic:claude-3-opus-20240229")

// Use consistently
result, _ := ai.GenerateText(ctx, ai.GenerateTextOptions{
    Model:  model,
    Prompt: "Hello!",
})
```

See the [Provider Registry documentation](https://goaisdk.com/docs/ai-sdk-core/provider-management.md) for more details.

## Next Steps

- Learn about [Prompts](https://goaisdk.com/docs/foundations/prompts.md)
- Explore [Tools and Tool Calling](https://goaisdk.com/docs/foundations/tools.md)
- Understand [Streaming](https://goaisdk.com/docs/foundations/streaming.md)
- Check out individual [Provider Documentation](https://goaisdk.com/docs/providers/overview.md)

## See Also

- [Core API Overview](https://goaisdk.com/docs/ai-sdk-core/overview.md)
- [Generating Text](https://goaisdk.com/docs/ai-sdk-core/generating-text.md)
- [Provider Management](https://goaisdk.com/docs/ai-sdk-core/provider-management.md)
- [Registry API Reference](https://goaisdk.com/docs/reference/registry/provider-registry.md)
