Skip to content

Anthropic Plugin

The Anthropic plugin provides access to Claude models through OpenAI-compatible endpoints in Go.

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.

  • 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
import (
"github.com/firebase/genkit/go/plugins/compat_oai/anthropic"
"github.com/openai/openai-go/option"
)
// Initialize Anthropic plugin
claude := &anthropic.Anthropic{
Opts: []option.RequestOption{
option.WithAPIKey("YOUR_ANTHROPIC_API_KEY"),
},
}
g, err := genkit.Init(ctx, genkit.WithPlugins(claude))
// Use Claude for tasks requiring reasoning
model := 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."),
)

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 tasks
openaiModel := oai.Model(g, "gpt-4o")
embedder := oai.Embedder(g, "text-embedding-3-large")
// Use Anthropic for reasoning and analysis
claudeModel := claude.Model(g, "claude-3-7-sonnet-20250219")

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