Documentation
¶
Index ¶
- Constants
- func DefaultOptions() []llm.Option
- func MaybeRegister(reg *llm.Registry)
- type ModelData
- type Provider
- func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)
- func (p *Provider) DefaultModel() string
- func (p *Provider) FetchModels(ctx context.Context) ([]llm.Model, error)
- func (p *Provider) Models() []llm.Model
- func (p *Provider) Name() string
- func (p *Provider) WithDefaultModel(modelID string) *Provider
Constants ¶
const (
// DefaultModel is the recommended default model for OpenRouter
DefaultModel = "anthropic/claude-sonnet-4.5"
)
const (
EnvOpenRouterAPIKey = "OPENROUTER_API_KEY"
)
Environment variable names for OpenRouter configuration.
Variables ¶
This section is empty.
Functions ¶
func DefaultOptions ¶ added in v0.12.0
DefaultOptions returns the default options for OpenRouter. Base URL defaults to https://openrouter.ai/api. API key should be provided via WithAPIKey() or WithAPIKeyFunc().
func MaybeRegister ¶ added in v0.13.0
MaybeRegister registers the OpenRouter provider if an API key is available. Checks OPENROUTER_API_KEY environment variable.
Types ¶
type ModelData ¶
type ModelData struct {
ID string `json:"id"`
CanonicalSlug string `json:"canonical_slug"`
HuggingFaceID string `json:"hugging_face_id"`
Name string `json:"name"`
Created int64 `json:"created"`
Description string `json:"description"`
ContextLength int `json:"context_length"`
Architecture struct {
Modality string `json:"modality"`
InputModalities []string `json:"input_modalities"`
OutputModalities []string `json:"output_modalities"`
Tokenizer string `json:"tokenizer"`
InstructType *string `json:"instruct_type"`
} `json:"architecture"`
Pricing struct {
Prompt string `json:"prompt"`
Completion string `json:"completion"`
InputCacheRead string `json:"input_cache_read"`
} `json:"pricing"`
TopProvider struct {
ContextLength int `json:"context_length"`
MaxCompletionTokens int `json:"max_completion_tokens"`
IsModerated bool `json:"is_moderated"`
} `json:"top_provider"`
PerRequestLimits interface{} `json:"per_request_limits"`
SupportedParameters []string `json:"supported_parameters"`
DefaultParameters map[string]interface{} `json:"default_parameters"`
}
ModelData represents the full structure of a model from OpenRouter API
func GetModelData ¶
GetModelData returns the full model data from the embedded models.json file. This includes pricing, context length, supported parameters, and other metadata.
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the OpenRouter LLM backend.
func New ¶
New creates a new OpenRouter provider. Options are applied on top of DefaultOptions().
Example usage:
// With API key
p := openrouter.New(llm.WithAPIKey("sk-or-..."))
// With API key from environment
p := openrouter.New(llm.APIKeyFromEnv("OPENROUTER_API_KEY"))
// With dynamic API key resolution
p := openrouter.New(llm.WithAPIKeyFunc(func(ctx context.Context) (string, error) {
return secretStore.Get(ctx, "openrouter-key")
}))
func (*Provider) CreateStream ¶
func (p *Provider) CreateStream(ctx context.Context, opts llm.StreamOptions) (<-chan llm.StreamEvent, error)
func (*Provider) DefaultModel ¶
DefaultModel returns the configured default model ID.
func (*Provider) FetchModels ¶
func (*Provider) Models ¶
Models returns the curated list of tool-enabled models from the embedded models.json file. This includes 229 models from various providers that support tool calling.
func (*Provider) WithDefaultModel ¶
WithDefaultModel sets the default model to use.