Skip to content

Anthropic plugin

The Anthropic plugin provides access to Anthropic’s Claude models in Go.

import "github.com/firebase/genkit/go/plugins/anthropic"
g := genkit.Init(context.Background(), genkit.WithPlugins(&anthropic.Anthropic{}))

You must provide an API key from Anthropic. You can get an API key from the Anthropic Console. The plugin will automatically use the ANTHROPIC_API_KEY environment variable.

  • claude-sonnet-4-5 - Claude Sonnet 4.5 with extended thinking support
  • claude-sonnet-4 - Claude Sonnet 4
  • claude-opus-4 - Claude Opus 4
  • claude-3-5-haiku - Fast and efficient Claude 3.5 Haiku
  • claude-3-haiku - Fastest Claude 3 model
import (
"github.com/firebase/genkit/go/plugins/anthropic"
)
// Initialize Anthropic plugin
g := genkit.Init(ctx, genkit.WithPlugins(&anthropic.Anthropic{}))
// Use Claude for tasks requiring reasoning
model := anthropic.Model(g, "claude-sonnet-4-6")
resp, err := genkit.Generate(ctx, g,
ai.WithModel(model),
ai.WithPrompt("Analyze this complex problem step by step."),
)

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/anthropic"
)
oai := &openai.OpenAI{APIKey: "YOUR_OPENAI_KEY"}
claude := &anthropic.Anthropic{}
g := genkit.Init(ctx, genkit.WithPlugins(oai, claude))
// Use OpenAI for embeddings and tool-heavy tasks
openaiModel := oai.Model(g, "gpt-4o")
embedder := oai.Embedder(g, "text-embedding-3-large")
// Use Anthropic for reasoning and analysis
claudeModel := anthropic.Model(g, "claude-sonnet-4-6")

Claude models support vision capabilities:

// Works with Claude models
resp, 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),
),
),
)

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

Anthropic models support specific configuration options provided by the Anthropic SDK:

import "github.com/anthropics/anthropic-sdk-go"
config := &anthropic.MessageNewParams{
Temperature: anthropic.Float(0.7),
MaxTokens: anthropic.Int(1000),
TopP: anthropic.Float(0.9),
}
resp, err := genkit.Generate(ctx, g,
ai.WithModel(model),
ai.WithPrompt("Your prompt here"),
ai.WithConfig(config),
)