Anthropic Plugin
The Anthropic plugin provides access to Claude models through OpenAI-compatible endpoints in Go.
Configuration
Section titled “Configuration”import "github.com/firebase/genkit/go/plugins/compat_oai/anthropic"
g := genkit.Init(context.Background(), genkit.WithPlugins(&anthropic.Anthropic{ Opts: []option.RequestOption{ option.WithAPIKey("YOUR_ANTHROPIC_API_KEY"), },}))
You must provide an API key from Anthropic. You can get an API key from the Anthropic Console.
Supported Models
Section titled “Supported Models”- claude-3-7-sonnet-20250219 - Latest Claude 3.7 Sonnet with advanced capabilities
- claude-3-5-haiku-20241022 - Fast and efficient Claude 3.5 Haiku
- claude-3-5-sonnet-20240620 - Balanced Claude 3.5 Sonnet
- claude-3-opus-20240229 - Most capable Claude 3 model
- claude-3-haiku-20240307 - Fastest Claude 3 model
Usage Example
Section titled “Usage Example”import ( "github.com/firebase/genkit/go/plugins/compat_oai/anthropic" "github.com/openai/openai-go/option")
// Initialize Anthropic pluginclaude := &anthropic.Anthropic{ Opts: []option.RequestOption{ option.WithAPIKey("YOUR_ANTHROPIC_API_KEY"), },}g, err := genkit.Init(ctx, genkit.WithPlugins(claude))
// Use Claude for tasks requiring reasoningmodel := claude.Model(g, "claude-3-7-sonnet-20250219")resp, err := genkit.Generate(ctx, g, ai.WithModel(model), ai.WithPrompt("Analyze this complex problem step by step."),)
Using Multiple Providers
Section titled “Using Multiple Providers”You can use both OpenAI and Anthropic providers in the same application:
import ( "github.com/firebase/genkit/go/plugins/compat_oai/openai" "github.com/firebase/genkit/go/plugins/compat_oai/anthropic")
oai := &openai.OpenAI{APIKey: "YOUR_OPENAI_KEY"}claude := &anthropic.Anthropic{ Opts: []option.RequestOption{ option.WithAPIKey("YOUR_ANTHROPIC_KEY"), },}
g, err := genkit.Init(ctx, genkit.WithPlugins(oai, claude))
// Use OpenAI for embeddings and tool-heavy tasksopenaiModel := oai.Model(g, "gpt-4o")embedder := oai.Embedder(g, "text-embedding-3-large")
// Use Anthropic for reasoning and analysisclaudeModel := claude.Model(g, "claude-3-7-sonnet-20250219")
Advanced Features
Section titled “Advanced Features”Multimodal Support
Section titled “Multimodal Support”Claude models support vision capabilities:
// Works with Claude modelsresp, err := genkit.Generate(ctx, g, ai.WithModel(model), ai.WithMessages( ai.NewUserMessage( ai.NewTextPart("What do you see in this image?"), ai.NewMediaPart("image/jpeg", imageData), ), ),)
Streaming
Section titled “Streaming”Claude models support streaming responses:
resp, err := genkit.Generate(ctx, g, ai.WithModel(model), ai.WithPrompt("Write a long explanation."), ai.WithStreaming(func(ctx context.Context, chunk *ai.ModelResponseChunk) error { for _, content := range chunk.Content { fmt.Print(content.Text) } return nil }),)
Configuration
Section titled “Configuration”Anthropic models support OpenAI-compatible configuration:
import "github.com/firebase/genkit/go/plugins/compat_oai"
config := &compat_oai.OpenAIConfig{ Temperature: 0.7, MaxOutputTokens: 1000, TopP: 0.9, StopSequences: []string{"END"},}
resp, err := genkit.Generate(ctx, g, ai.WithModel(model), ai.WithPrompt("Your prompt here"), ai.WithConfig(config),)