Skip to content

Latest commit

 

History

48 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Omni-OpenRouter

Go CI Go Lint Go SAST Docs Docs Visualization License

OpenRouter thick provider for omnillm, providing access to 300+ AI models through the unified omnillm interface.

Installation

go get github.com/plexusone/omni-openrouter

Usage

As an omnillm Provider

Import the package for side effects to register the OpenRouter provider:

package main

import (
    "context"
    "os"

    _ "github.com/plexusone/omni-openrouter/omnillm"
    "github.com/plexusone/omnillm"
)

func main() {
    client, err := omnillm.NewChatClient(omnillm.Config{
        Provider: "openrouter",
        APIKey:   os.Getenv("OPENROUTER_API_KEY"),
        Model:    "anthropic/claude-3.5-sonnet",
    })
    if err != nil {
        panic(err)
    }
    defer client.Close()

    // Use the client as usual
    resp, err := client.CreateChatCompletion(context.Background(), &omnillm.ChatCompletionRequest{
        Model: "anthropic/claude-3.5-sonnet",
        Messages: []omnillm.Message{
            {Role: omnillm.RoleUser, Content: "Hello!"},
        },
    })
    // ...
}

OAuth PKCE Authentication

For interactive applications, you can use OAuth to authenticate:

package main

import (
    "context"
    "fmt"

    "github.com/plexusone/omni-openrouter/auth"
)

func main() {
    ctx := context.Background()

    // Perform OAuth login (opens browser)
    apiKey, err := auth.Login(ctx)
    if err != nil {
        panic(err)
    }

    fmt.Printf("API key obtained: %s...\n", apiKey[:10])

    // Later, retrieve the stored key
    storedKey, err := auth.LoadAPIKey(ctx)
    if err != nil {
        panic(err)
    }
    // ...
}

Supported Models

OpenRouter provides access to models from:

  • Anthropic: Claude 4 Opus, Claude 4 Sonnet, Claude 3.5 Sonnet, etc.
  • OpenAI: GPT-4 Turbo, GPT-4, GPT-3.5 Turbo, etc.
  • Google: Gemini Pro, Gemini Ultra, etc.
  • Meta: Llama 3, Llama 2, etc.
  • Mistral: Mixtral, Mistral Large, etc.
  • And 300+ more models

Model identifiers follow the format provider/model-name, for example:

  • anthropic/claude-opus-4-20250514
  • openai/gpt-4-turbo
  • google/gemini-pro
  • meta-llama/llama-3-70b-instruct

Features

  • Full tool/function calling support
  • Streaming completions
  • Vision support (for compatible models)
  • JSON mode (for compatible models)
  • Reasoning effort control
  • Automatic error classification for intelligent fallback

Reasoning

OpenRouter supports the reasoning_effort parameter with extended values:

import omnillm "github.com/plexusone/omnillm-core"

effort := omnillm.ReasoningEffortHigh
response, err := client.CreateChatCompletion(ctx, &omnillm.ChatCompletionRequest{
    Model:           "anthropic/claude-3.5-sonnet",
    ReasoningEffort: &effort,
    Messages:        messages,
})

Supported Values

OpenRouter supports extended reasoning_effort values beyond the standard four:

Value Description
"none" Disable reasoning
"minimal" Minimal reasoning
"low" Light reasoning
"medium" Moderate reasoning
"high" Deep reasoning
"xhigh" Extra-high reasoning
"max" Maximum reasoning

The standard omnillm constants (ReasoningEffortNone, ReasoningEffortLow, ReasoningEffortMedium, ReasoningEffortHigh) work directly. For extended values like "xhigh" or "max", set the string value directly.

See Reasoning Feature Guide for cross-provider usage.

Configuration

The provider accepts the following configuration:

Field Description
APIKey OpenRouter API key (required)
BaseURL Custom API endpoint (optional)
SiteURL Your application URL for attribution (optional)
SiteName Your application name for attribution (optional)

License

MIT

About

OpenRouter thick provider for omnillm, providing access to 300+ AI models through the unified omnillm interface.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Contributors

Languages