OrcaRouter Lite

repository·main·Indexed 19 days ago

https://github.com/continuum-ai-corp/orcarouter-lite

A self-hosted, OpenAI-compatible LLM router (v0.1.0) that manages multiple model providers through a single interface. Key features include automatic cost-optimization via `model="auto"`, cross-provider prompt caching, and a built-in dashboard. It supports integrations with tools like Continue.dev, Aider, LangChain, LlamaIndex, Vercel AI SDK, and Cursor, and can be deployed via Docker Compose with a managed hosted service fallback.

Tokens
23.1K
Snippets
82
Records
124
Agent score
63%

What's inside orcarouter-lite

  1. Key Features and Roadmap

    main

    OrcaRouter Lite provides several core capabilities for managing LLM requests:

    • OpenAI Compatibility: Supports standard Chat-Completions and Streaming (SSE).
    • model="auto": Automatically routes requests to the most cost-effective suitable model.
    • Hosted Fallback: Ability to use the hosted version as an upstream provider.
    • Security: Encrypted BYOK (Bring Your Own Key) storage in memory.
    • Analytics: Local dashboard for monitoring usage.
    • Caching: Provider-agnostic prompt caching.
    • Integrations: Compatible with tools like Continue.dev, Aider, LangChain, Cursor, and Vercel-AI-SDK.

    Note: Embeddings and Image-Gen-Proxy are planned for future releases.

  2. Use the `model="auto"` feature

    main

    The signature feature of OrcaRouter is model="auto". When you pass this value, OrcaRouter automatically selects the cheapest model from your configured providers that meets the specific capability requirements of your request (such as tools, vision, or json_mode).

    This eliminates the need for manual routing logic or hardcoded model names in your application code. The specific model selected is returned in the x-orca-resolved-model response header.

    client.chat.completions.create(
        model="auto",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "What's in this image?"},
            {"type": "image_url", "image_url": {"url": "data:..."}},
        ]}],
    )
    # → Routes to the cheapest model supporting VISION
  3. How OrcaRouter Lite works (Architecture)

    main

    OrcaRouter Lite acts as an OpenAI-compatible proxy layer that provides intelligent model routing. The architecture is divided into the main application and supporting packages:

    Core Application (app/)

    • Routing Logic: auto_routing.py handles the model="auto" capability and cost scoring. router_cache.py manages single-workspace routing.
    • Caching: prompt_cache.py provides cross-provider exact-match caching (using Redis or in-memory LRU).
    • API Surface: The /v1/chat/completions endpoint (in routes/chat.py) supports both blocking and streaming (SSE) requests.
    • Management Endpoints: Includes routes for /v1/models, provider CRUD, strategy configuration, analytics (spend, latency, savings), and API key management.
    • Security: middleware/auth.py validates sk-orca-* keys.

    Supporting Packages

    • litellm_adapter/: Provides the router wrapper and a catalog of over 100 models.
    • auth/: Handles hashing and AES-256-GCM encryption.
    • db/: Manages database models, engines, and sessions.
  4. How `model="auto"` works

    main

    The model="auto" feature is the core capability of OrcaRouter. When you pass model="auto" in a chat completion request, OrcaRouter automatically selects the least expensive model among your configured providers that meets the specific requirements of your request (such as tools support, vision capabilities, or json_mode).

    This eliminates the need for manual routing logic or cost-optimization code in your application. The specific model chosen by the router is returned in the x-orca-resolved-model response header.

    client.chat.completions.create(
        model="auto",
        messages=[{"role": "user", "content": [
            {"type": "text", "text": "What's in this image?"},
            {"type": "image_url", "image_url": {"url": "data:..."}},
        ]}],
    )
    # → routes to the cheapest VISION-compatible model covered by your keys
  5. Use Hosted OrcaRouter as an Upstream Fallback

    main

    You can combine self-hosting with the hosted service by setting the ORCAROUTER_API_KEY environment variable with your sk-orca-* key from www.orcarouter.ai. This makes the hosted service an additional provider in your routing chain, covering models that your local keys might not support. This is useful for testing without local keys, logging via Lite, or providing a safety net (failover) if local providers fail.

    # .env
    ORCAROUTER_API_KEY=sk-orca-hosted-abc...
  6. Provider-wide Prompt Caching

    main

    OrcaRouter implements a deterministic prompt cache for requests with temperature=0 or a pinned seed. If a request with the same payload is repeated, it is served from the cache, bypassing the upstream provider and costing $0.

    • If a cache hit occurs, the response includes the header x-orca-cache: HIT.
    • If it is a miss, it returns x-orca-cache: MISS.
    • The backend uses Redis if REDIS_URL is set; otherwise, it uses an in-process LRU cache.
    # First request (Miss)
    $ curl ... -d '{"model":"auto","messages":[...], "temperature": 0}' -i
    HTTP/1.1 200 OK
    x-orca-cache: MISS
    x-orca-resolved-model: gpt-4o-mini
    
    # Second request (Hit)
    $ curl ... # same payload
    HTTP/1.1 200 OK
    x-orca-cache: HIT
  7. Use the `model="auto"` routing feature

    main
    The headline feature of OrcaRouter Lite is the model="auto" capability. When you pass model="auto" in your request, the router automatically selects the most cost-effective and capable model for your specific task based on its internal cost scoring and routing logic.
  8. OrcaRouter Lite Architecture Overview

    main

    OrcaRouter Lite is built as a FastAPI application with an OpenAI-compatible interface. Key components include:

    • Routing & Intelligence: auto_routing.py handles the model="auto" logic and cost scoring. router_cache.py manages single-workspace routing.
    • Caching: prompt_cache.py provides cross-provider exact-match caching using either Redis or an in-memory LRU.
    • API Surface: The /v1/chat/completions endpoint supports both blocking and streaming (SSE) responses. Other endpoints include /v1/models, /v1/providers (BYOK CRUD), /v1/routing (strategy config), and /v1/analytics.
    • Security: middleware/auth.py validates sk-orca-* keys, and the auth package uses AES-256-GCM for encryption.
    • Adapters: The litellm_adapter package provides a router wrapper and a catalog of over 100 models.
  9. How OrcaRouter Lite works: Architecture and Core Components

    main

    OrcaRouter Lite acts as an OpenAI-compatible proxy that enables intelligent model routing. Its architecture is divided into a FastAPI application layer and a core package layer:

    Application Layer (app/)

    • Routing Logic: auto_routing.py implements the model="auto" capability by scoring models based on cost and capability. router_cache.py manages single-workspace routing.
    • Caching: prompt_cache.py provides cross-provider exact-match caching using either Redis or an in-memory LRU.
    • API Endpoints (routes/):
      • /v1/chat/completions: Supports both blocking and streaming (SSE) chat completions.
      • /v1/models: Lists available models.
      • /v1/hosted: Provides hosted-fallback status for dashboards.
      • /v1/providers: CRUD operations for BYOK (Bring Your Own Key) providers.
      • /v1/analytics: Provides data on recent spend, latency, savings, and unreachable providers.
      • /v1/keys: Management of API keys (list, rotate, revoke).
    • Security: middleware/auth.py validates sk-orca-* keys.

    Core Package (packages/)

    • litellm_adapter/: A wrapper providing access to a catalog of over 100 models.
    • auth/: Handles security using hashing and AES-256-GCM.
    • db/: Manages database models, engines, and sessions.
  10. Inter-provider prompt caching

    main

    OrcaRouter provides deterministic request caching. If a request is deterministic (e.g., temperature=0 or a fixed seed), it is served from the cache on subsequent calls. This works across all providers.

    • If using Redis (via REDIS_URL), the cache is distributed.
    • If Redis is not configured, an in-process LRU cache is used.
    • Cache hits are identified by the x-orca-cache: HIT header and cost $0.
    # First request (MISS)
    $ curl ... -d '{"model":"auto","messages":[...], "temperature": 0}' -i
    HTTP/1.1 200 OK
    x-orca-cache: MISS
    x-orca-resolved-model: gpt-4o-mini
    
    # Second request (HIT)
    $ curl ... # same payload
    HTTP/1.1 200 OK
    x-orca-cache: HIT
  11. Reference: Prompt Caching and Savings

    main

    OrcaRouter includes built-in prompt caching and cost analysis features.

    Prompt Caching: For deterministic requests (temperature=0 or a fixed seed), OrcaRouter caches the response. If a cache hit occurs, the response is returned immediately with the header x-orca-cache: HIT at $0 cost.

    Savings Analytics: You can compare your actual spend against a baseline (e.g., 'what if I always used GPT-4') using the analytics endpoint.

    # Check savings against a GPT-4 baseline for the last 7 days
    curl ... /v1/analytics/savings?baseline=gpt-4o&days=7
    
    # Example Cache Hit Header
    # HTTP/1.1 200 OK
    # x-orca-cache: HIT
  12. Cross-provider Prompt Caching

    main

    OrcaRouter Lite implements prompt caching for deterministic requests (where temperature=0 or a seed is provided). This works across all providers.

    • If a match is found, the response is served instantly with the header x-orca-cache: HIT at $0 cost.
    • If no match is found, the header x-orca-cache: MISS is returned.
    • The backend uses Redis if REDIS_URL is set; otherwise, it uses an in-process LRU cache.
    # First request (MISS)
    $ curl ... -d '{"model":"auto","messages":[...], "temperature": 0}' -i
    HTTP/1.1 200 OK
    x-orca-cache: MISS
    x-orca-resolved-model: gpt-4o-mini
    
    # Second request (HIT)
    $ curl ...  # same payload
    HTTP/1.1 200 OK
    x-orca-cache: HIT