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-opus-4-8 - Most capable model for complex reasoning and agentic tasks
  • claude-opus-4-7 - Previous-generation Opus, highly capable for long-horizon work
  • claude-sonnet-4-6 - Balanced model with extended thinking support
  • claude-haiku-4-5 - Fastest and most cost-effective 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-5.5")
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),
)