Skip to content

OpenAI plugin

The OpenAI plugin provides access to OpenAI models.

import "github.com/firebase/genkit/go/plugins/compat_oai/openai"
g := genkit.Init(context.Background(), genkit.WithPlugins(&openai.OpenAI{
APIKey: "YOUR_OPENAI_API_KEY", // or set OPENAI_API_KEY env var
}))
  • gpt-5.5 - Current flagship model for complex reasoning, coding, and agentic tasks, with adjustable reasoning effort
  • gpt-5.5-pro - Highest-capability variant for the hardest problems
  • gpt-5 - Previous generation flagship, still available
  • gpt-5.4-mini - Faster, cost-effective model that balances quality and latency
  • gpt-5.4-nano - Most efficient model for high-volume, latency-sensitive tasks
  • gpt-4.1 - Cost-effective model with very large context window
  • gpt-4.1-mini - Faster, cost-effective GPT-4.1 variant
  • gpt-4.1-nano - Ultra-efficient GPT-4.1 variant
  • text-embedding-3-large - Most capable embedding model
  • text-embedding-3-small - Fast and efficient embedding model
import (
"github.com/firebase/genkit/go/plugins/compat_oai/openai"
"github.com/firebase/genkit/go/plugins/compat_oai"
)
// Initialize Genkit with the OpenAI plugin
g := genkit.Init(ctx, genkit.WithPlugins(&openai.OpenAI{APIKey: "YOUR_API_KEY"}))
// Use GPT-5.5 for general tasks
resp, err := genkit.Generate(ctx, g,
ai.WithModelName("openai/gpt-5.5"),
ai.WithPrompt("Explain quantum computing."),
)
// Use embeddings
embeds, err := genkit.Embed(ctx, g,
ai.WithEmbedderName("openai/text-embedding-3-large"),
ai.WithTextDocs("Hello, world!"),
)
import (
"github.com/openai/openai-go"
oai "github.com/firebase/genkit/go/plugins/compat_oai"
)
// custom provider plugin parameters
g := genkit.Init(ctx, genkit.WithPlugins(&oai.OpenAICompatible{
Provider: "custom-provider",
APIKey: "api-key",
BaseURL: "custom-url",
}),
genkit.WithDefaultModel("custom-provider/id"))
resp, err := genkit.Generate(ctx, g, ai.WithPrompt("Tell me a joke"))

OpenAI models support tool calling:

// Define a tool
weatherTool := genkit.DefineTool(g, "get_weather", "Get current weather",
func(ctx *ai.ToolContext, input struct{City string}) (string, error) {
return fmt.Sprintf("It's sunny in %s", input.City), nil
})
// Use with GPT models
resp, err := genkit.Generate(ctx, g,
ai.WithModelName("openai/gpt-5.5"),
ai.WithPrompt("What's the weather like in San Francisco?"),
ai.WithTools(weatherTool),
)

OpenAI models support vision capabilities:

// Works with GPT-5 models
resp, err := genkit.Generate(ctx, g,
ai.WithModelName("openai/gpt-5.5"),
ai.WithMessages(
ai.NewUserMessage(
ai.NewTextPart("What do you see in this image?"),
ai.NewMediaPart("image/jpeg", imageData),
),
),
)

OpenAI models support streaming responses:

resp, err := genkit.Generate(ctx, g,
ai.WithModelName("openai/gpt-5.5"),
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
}),
)