From becda53a17be7c8c8a254bc914ff92bb01ba8d9c Mon Sep 17 00:00:00 2001 From: 1bcMax Date: Thu, 26 Mar 2026 10:26:12 -0700 Subject: [PATCH] feat: add ClawRouter as a provider for cost-optimized model routing (#11751) * feat: add ClawRouter as a provider for cost-optimized model routing ClawRouter is an open-source LLM router that automatically selects the cheapest capable model for each request based on prompt complexity, providing 78-96% cost savings on blended inference costs. Changes: - Add ClawRouterApi class extending OpenAI adapter - Add 'clawrouter' provider to the type system - Add ClawRouter models (auto, free, eco) - Add ClawRouter provider config with UI setup - Add ClawRouter logo - Add documentation (clawrouter.mdx) Closes #10843 * docs: enhance ClawRouter documentation - Add ClawRouter to providers overview - Expand documentation with: - Model capabilities configuration - Multiple roles setup - Troubleshooting section - Cost monitoring - Comparison with OpenRouter - Complexity dimensions explanation * feat: add ClawRouter to core/llm/llms - Add ClawRouter.ts extending OpenAI base class - Register ClawRouter in llms/index.ts * feat: add User-Agent headers for ClawRouter integration tracking - Add 'User-Agent: Continue/IDE' header to identify Continue requests - Add 'X-Continue-Provider: clawrouter' header for routing analytics - Enhanced documentation with features list This helps ClawRouter optimize routing decisions based on integration source and enables better analytics for the Continue community. * feat: complete ClawRouter integration with full provider support - Add clawrouter to PROVIDER_HANDLES_TEMPLATING (autodetect.ts) - Add clawrouter to PROVIDER_SUPPORTS_IMAGES (autodetect.ts) - Add clawrouter tool support function (toolSupport.ts) - Add supportsReasoningField and supportsReasoningDetailsField - Add promptTemplates with osModelsEditPrompt - Match OpenRouter implementation patterns * feat: add ClawRouter to VS Code schema, docs nav, and AI SDK - Add clawrouter to VS Code config_schema.json provider enum - Add ClawRouter description in config_schema.json - Add clawrouter to docs.json navigation (top-level providers) - Add clawrouter to AI SDK PROVIDER_MAP * docs: add wallet setup and x402 payment documentation - Add Wallet & Payment Setup section to clawrouter.mdx - Document payment tiers (free/eco/auto) - Add wallet funding instructions (Solana/Base USDC) - Add spend control configuration - Update VS Code schema description with wallet info - Update provider longDescription with payment options * feat: add premium tier and enhanced ClawRouter features - Add blockrun/premium routing profile (mission-critical tasks) - Add dual-chain wallet support docs (Base EVM + Solana) - Add model exclusion documentation - Update routing profiles table with savings percentages - Update comparison table with auth/payment differences - Total 44+ models, 4 routing tiers * test: add ClawRouter unit tests - Add ClawRouter.vitest.ts (core/llm/llms) - Provider name verification - Default options validation - Reasoning field support - User-Agent header verification - Routing profiles acceptance - Add ClawRouter.test.ts (openai-adapters) - Default apiBase - Custom apiBase override - Continue headers - OpenAI standard headers - Add clawrouter tests to toolSupport.test.ts - blockrun/* routing profiles - Tool-supporting model patterns * docs: add routing profile switching and enhanced error handling docs - Add 'Switching Between Routing Profiles' section with full examples - Add /model command tip for quick switching - Add 'Error Handling' section comparing Continue vs ClawRouter - Document automatic error recovery (429, 402, 500+, timeout) - Add response header documentation for diagnostics - Add AI-powered doctor command for troubleshooting * fix: address PR review feedback - move docs to /more, resize logo, add provider constants, fix docs example * fix: replace clawrouter logo with higher-res brand kit version (128x128) --- core/llm/autodetect.ts | 2 + core/llm/llms/ClawRouter.ts | 53 ++ core/llm/llms/ClawRouter.vitest.ts | 50 ++ core/llm/llms/index.ts | 2 + core/llm/toolSupport.test.ts | 23 + core/llm/toolSupport.ts | 36 ++ .../model-providers/more/clawrouter.mdx | 507 ++++++++++++++++++ docs/customize/model-providers/overview.mdx | 1 + docs/docs.json | 1 + extensions/vscode/config_schema.json | 2 + gui/public/logos/clawrouter.png | Bin 0 -> 2362 bytes gui/src/pages/AddNewModel/configs/models.ts | 55 ++ .../pages/AddNewModel/configs/providers.ts | 44 ++ packages/openai-adapters/src/apis/AiSdk.ts | 5 + .../src/apis/ClawRouter.test.ts | 42 ++ .../openai-adapters/src/apis/ClawRouter.ts | 42 ++ packages/openai-adapters/src/index.ts | 3 + packages/openai-adapters/src/types.ts | 1 + 18 files changed, 869 insertions(+) create mode 100644 core/llm/llms/ClawRouter.ts create mode 100644 core/llm/llms/ClawRouter.vitest.ts create mode 100644 docs/customize/model-providers/more/clawrouter.mdx create mode 100644 gui/public/logos/clawrouter.png create mode 100644 packages/openai-adapters/src/apis/ClawRouter.test.ts create mode 100644 packages/openai-adapters/src/apis/ClawRouter.ts diff --git a/core/llm/autodetect.ts b/core/llm/autodetect.ts index d401ad5a0..0f1c4600f 100644 --- a/core/llm/autodetect.ts +++ b/core/llm/autodetect.ts @@ -65,6 +65,7 @@ const PROVIDER_HANDLES_TEMPLATING: string[] = [ "nebius", "relace", "openrouter", + "clawrouter", "deepseek", "xAI", "minimax", @@ -123,6 +124,7 @@ const PROVIDER_SUPPORTS_IMAGES: string[] = [ "sagemaker", "continue-proxy", "openrouter", + "clawrouter", "venice", "sambanova", "vertexai", diff --git a/core/llm/llms/ClawRouter.ts b/core/llm/llms/ClawRouter.ts new file mode 100644 index 000000000..2cdb9a8ce --- /dev/null +++ b/core/llm/llms/ClawRouter.ts @@ -0,0 +1,53 @@ +import { LLMOptions } from "../../index.js"; +import { osModelsEditPrompt } from "../templates/edit.js"; + +import OpenAI from "./OpenAI.js"; + +// Get Continue version from package.json at build time +const CONTINUE_VERSION = process.env.npm_package_version || "unknown"; + +/** + * ClawRouter LLM Provider + * + * ClawRouter is an open-source LLM router that automatically selects the + * cheapest capable model for each request based on prompt complexity, + * providing 78-96% cost savings on blended inference costs. + * + * Features: + * - 15-dimension prompt complexity scoring + * - Automatic model selection (cheap → capable based on task) + * - OpenAI-compatible API at localhost:1337 + * - Support for multiple routing tiers (auto, free, eco) + * + * @see https://github.com/BlockRunAI/ClawRouter + */ +class ClawRouter extends OpenAI { + static providerName = "clawrouter"; + + // ClawRouter can route to models that support reasoning fields + protected supportsReasoningField = true; + protected supportsReasoningDetailsField = true; + + static defaultOptions: Partial = { + apiBase: "http://localhost:1337/v1/", + model: "blockrun/auto", + promptTemplates: { + edit: osModelsEditPrompt, + }, + useLegacyCompletionsEndpoint: false, + }; + + /** + * Override headers to include Continue-specific User-Agent + * This helps ClawRouter track integration usage and optimize accordingly + */ + protected _getHeaders() { + return { + ...super._getHeaders(), + "User-Agent": `Continue/${CONTINUE_VERSION}`, + "X-Continue-Provider": "clawrouter", + }; + } +} + +export default ClawRouter; diff --git a/core/llm/llms/ClawRouter.vitest.ts b/core/llm/llms/ClawRouter.vitest.ts new file mode 100644 index 000000000..fa3af73f1 --- /dev/null +++ b/core/llm/llms/ClawRouter.vitest.ts @@ -0,0 +1,50 @@ +import { describe, expect, it } from "vitest"; + +import ClawRouter from "./ClawRouter"; + +describe("ClawRouter", () => { + it("should have correct provider name", () => { + expect(ClawRouter.providerName).toBe("clawrouter"); + }); + + it("should have correct default options", () => { + expect(ClawRouter.defaultOptions.apiBase).toBe("http://localhost:1337/v1/"); + expect(ClawRouter.defaultOptions.model).toBe("blockrun/auto"); + expect(ClawRouter.defaultOptions.useLegacyCompletionsEndpoint).toBe(false); + }); + + it("should support reasoning fields", () => { + const clawRouter = new ClawRouter({ + model: "blockrun/auto", + }); + + // ClawRouter routes to models that may support reasoning + expect(clawRouter["supportsReasoningField"]).toBe(true); + expect(clawRouter["supportsReasoningDetailsField"]).toBe(true); + }); + + it("should include Continue User-Agent header", () => { + const clawRouter = new ClawRouter({ + model: "blockrun/auto", + }); + + const headers = clawRouter["_getHeaders"](); + + expect(headers["User-Agent"]).toMatch(/^Continue\//); + expect(headers["X-Continue-Provider"]).toBe("clawrouter"); + }); + + it("should accept all routing profiles", () => { + const profiles = [ + "blockrun/auto", + "blockrun/eco", + "blockrun/premium", + "blockrun/free", + ]; + + for (const profile of profiles) { + const clawRouter = new ClawRouter({ model: profile }); + expect(clawRouter.model).toBe(profile); + } + }); +}); diff --git a/core/llm/llms/index.ts b/core/llm/llms/index.ts index 8b48d4c51..453b2d90c 100644 --- a/core/llm/llms/index.ts +++ b/core/llm/llms/index.ts @@ -50,6 +50,7 @@ import Nvidia from "./Nvidia"; import Ollama from "./Ollama"; import OpenAI from "./OpenAI"; import OpenRouter from "./OpenRouter"; +import ClawRouter from "./ClawRouter"; import OVHcloud from "./OVHcloud"; import { Relace } from "./Relace"; import Replicate from "./Replicate"; @@ -111,6 +112,7 @@ export const LLMClasses = [ Azure, WatsonX, OpenRouter, + ClawRouter, Nvidia, Vllm, SambaNova, diff --git a/core/llm/toolSupport.test.ts b/core/llm/toolSupport.test.ts index 00ee1c30e..57b9e6d80 100644 --- a/core/llm/toolSupport.test.ts +++ b/core/llm/toolSupport.test.ts @@ -419,6 +419,29 @@ describe("PROVIDER_TOOL_SUPPORT", () => { }); }); + describe("clawrouter", () => { + const supportsFn = PROVIDER_TOOL_SUPPORT["clawrouter"]; + + it("should return true for blockrun routing profiles", () => { + expect(supportsFn("blockrun/auto")).toBe(true); + expect(supportsFn("blockrun/eco")).toBe(true); + expect(supportsFn("blockrun/premium")).toBe(true); + expect(supportsFn("blockrun/free")).toBe(true); + }); + + it("should return true for tool-supporting models", () => { + expect(supportsFn("gpt-4o")).toBe(true); + expect(supportsFn("claude-3-sonnet")).toBe(true); + expect(supportsFn("gemini-pro")).toBe(true); + expect(supportsFn("anthropic/claude-opus-4.6")).toBe(true); + }); + + it("should return false for non-tool-supporting patterns", () => { + expect(supportsFn("random-model")).toBe(false); + expect(supportsFn("")).toBe(false); + }); + }); + describe("edge cases", () => { it("should handle empty model names", () => { expect(PROVIDER_TOOL_SUPPORT["continue-proxy"]("")).toBe(false); diff --git a/core/llm/toolSupport.ts b/core/llm/toolSupport.ts index 4635d0293..e38a6de8d 100644 --- a/core/llm/toolSupport.ts +++ b/core/llm/toolSupport.ts @@ -401,6 +401,42 @@ export const PROVIDER_TOOL_SUPPORT: Record boolean> = return false; }, + clawrouter: (model) => { + // ClawRouter routes to various providers, so we check common tool-supporting patterns + const lower = model.toLowerCase(); + + // blockrun/* models are routing aliases - assume tool support + if (lower.startsWith("blockrun/")) { + return true; + } + + // Check for common tool-supporting model patterns + const toolSupportingPatterns = [ + "gpt-4", + "gpt-5", + "o1", + "o3", + "o4", + "claude-3", + "claude-4", + "sonnet", + "opus", + "haiku", + "gemini", + "command-r", + "mistral", + "mixtral", + "llama-3.1", + "llama-3.2", + "llama-3.3", + "llama-4", + "qwen3", + "qwen-2.5", + "deepseek", + ]; + + return toolSupportingPatterns.some((pattern) => lower.includes(pattern)); + }, zAI: (model) => { const lower = model.toLowerCase(); return lower.startsWith("glm-4") || lower.startsWith("glm-5"); diff --git a/docs/customize/model-providers/more/clawrouter.mdx b/docs/customize/model-providers/more/clawrouter.mdx new file mode 100644 index 000000000..7c91cf0ae --- /dev/null +++ b/docs/customize/model-providers/more/clawrouter.mdx @@ -0,0 +1,507 @@ +--- +title: "How to Configure ClawRouter with Continue" +sidebarTitle: "ClawRouter" +--- + + + ClawRouter is an open-source LLM router that automatically selects the cheapest capable model for each request based on prompt complexity, providing 78-96% cost savings. + + + + Get started with [ClawRouter on GitHub](https://github.com/BlockRunAI/ClawRouter) + + +## Installation + +ClawRouter runs locally and provides an OpenAI-compatible API: + +```bash +npx clawrouter +``` + +This starts the router at `http://localhost:1337`. + +You can also install it globally: + +```bash +npm install -g clawrouter +clawrouter +``` + +## Configuration + + + + ```yaml title="config.yaml" + name: My Config + version: 0.0.1 + schema: v1 + + models: + - name: ClawRouter Auto + provider: clawrouter + model: blockrun/auto + apiBase: http://localhost:1337/v1/ + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter Auto", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://localhost:1337/v1/" + } + ] + } + ``` + + + +## Available Models + +ClawRouter provides four routing profiles: + +| Model | Savings | Description | Best For | +|-------|---------|-------------|----------| +| `blockrun/auto` | 74-100% | Balanced routing based on prompt complexity | General use (recommended) | +| `blockrun/eco` | 95-100% | Cheapest possible models | Maximum savings | +| `blockrun/premium` | 0% | Best quality models (Opus, GPT-5.4 Pro) | Mission-critical tasks | +| `blockrun/free` | 100% | Free-tier models only (nvidia/gpt-oss-120b) | Zero cost testing | + +You can also specify any of the 44+ models directly (e.g., `anthropic/claude-sonnet-4.6`, `openai/gpt-5.4`, `xai/grok-4`). + +## How It Works + +ClawRouter uses a 15-dimension prompt complexity scoring system to analyze each request: + +- **Simple requests** (greetings, basic Q&A, simple edits) → routed to cheap models like Claude Haiku or Gemini Flash +- **Medium requests** (code explanations, refactoring) → routed to balanced models like Claude Sonnet or GPT-4o-mini +- **Complex requests** (architecture design, complex debugging) → routed to capable models like Claude Opus or GPT-4o + +This automatic routing provides significant cost savings while maintaining quality for complex tasks. + +### Complexity Dimensions + +The router analyzes prompts across dimensions including: +- Code complexity and language detection +- Reasoning depth required +- Context length and dependencies +- Domain expertise needed +- Output format requirements + +## Model Capabilities + +ClawRouter supports function calling and tool use through its underlying model providers. Capabilities are automatically inherited from the routed model. + + + + ```yaml title="config.yaml" + models: + - name: ClawRouter Auto + provider: clawrouter + model: blockrun/auto + apiBase: http://localhost:1337/v1/ + capabilities: + - tool_use + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter Auto", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://localhost:1337/v1/", + "capabilities": { + "tools": true + } + } + ] + } + ``` + + + +## Switching Between Routing Profiles + +Add multiple ClawRouter profiles to your config and switch via Continue's model picker: + + + + ```yaml title="config.yaml" + models: + # Default: automatic routing + - name: ClawRouter Auto + provider: clawrouter + model: blockrun/auto + apiBase: http://localhost:1337/v1/ + + # Maximum savings + - name: ClawRouter Eco + provider: clawrouter + model: blockrun/eco + apiBase: http://localhost:1337/v1/ + + # Best quality + - name: ClawRouter Premium + provider: clawrouter + model: blockrun/premium + apiBase: http://localhost:1337/v1/ + + # Zero cost + - name: ClawRouter Free + provider: clawrouter + model: blockrun/free + apiBase: http://localhost:1337/v1/ + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter Auto", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://localhost:1337/v1/" + }, + { + "title": "ClawRouter Eco", + "provider": "clawrouter", + "model": "blockrun/eco", + "apiBase": "http://localhost:1337/v1/" + }, + { + "title": "ClawRouter Premium", + "provider": "clawrouter", + "model": "blockrun/premium", + "apiBase": "http://localhost:1337/v1/" + }, + { + "title": "ClawRouter Free", + "provider": "clawrouter", + "model": "blockrun/free", + "apiBase": "http://localhost:1337/v1/" + } + ] + } + ``` + + + +Use the **model picker dropdown** in Continue's chat panel to switch between profiles. Each profile routes to different model tiers based on cost vs. quality trade-offs. + + + **Quick switch via CLI:** In the Continue chat, type `/model` followed by the profile name (e.g., `/model ClawRouter Eco`). + + +## Custom API Base + +If you're running ClawRouter on a different port or host: + + + + ```yaml title="config.yaml" + models: + - name: ClawRouter + provider: clawrouter + model: blockrun/auto + apiBase: http://your-server:8080/v1/ + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://your-server:8080/v1/" + } + ] + } + ``` + + + +## Using Multiple Roles + +You can configure ClawRouter for different Continue roles: + + + + ```yaml title="config.yaml" + models: + - name: ClawRouter Auto + provider: clawrouter + model: blockrun/auto + apiBase: http://localhost:1337/v1/ + roles: + - chat + - edit + - apply + + - name: ClawRouter Eco + provider: clawrouter + model: blockrun/eco + apiBase: http://localhost:1337/v1/ + roles: + - autocomplete + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter Auto", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://localhost:1337/v1/", + "roles": ["chat", "edit", "apply"] + } + ], + "tabAutocompleteModel": { + "title": "ClawRouter Eco", + "provider": "clawrouter", + "model": "blockrun/eco", + "apiBase": "http://localhost:1337/v1/" + } + } + ``` + + + +## API Keys + +ClawRouter manages upstream provider API keys internally. You configure them in ClawRouter, not in Continue. + +For self-hosted setups with custom authentication: + + + + ```yaml title="config.yaml" + models: + - name: ClawRouter + provider: clawrouter + model: blockrun/auto + apiBase: http://localhost:1337/v1/ + apiKey: ${{ secrets.CLAWROUTER_API_KEY }} + ``` + + + ```json title="config.json" + { + "models": [ + { + "title": "ClawRouter", + "provider": "clawrouter", + "model": "blockrun/auto", + "apiBase": "http://localhost:1337/v1/", + "apiKey": "" + } + ] + } + ``` + + + +## Wallet & Payment Setup + +ClawRouter supports crypto-native payments via the x402 protocol. On first run, ClawRouter automatically generates a wallet: + +```bash +npx clawrouter +# Wallet created: 5g3cB6... +# Fund your wallet to access premium models +``` + +### Payment Options + +| Tier | Description | Payment Required | +|------|-------------|------------------| +| `blockrun/free` | Free-tier models only | No | +| `blockrun/eco` | Economy models | Yes (low cost) | +| `blockrun/auto` | Automatic routing | Yes (pay-per-use) | + +### Funding Your Wallet + +ClawRouter supports both Solana and EVM wallets: + +```bash +# Check wallet balance +clawrouter wallet + +# View wallet address +clawrouter wallet address +``` + +Fund your wallet with USDC on Solana or Base for the lowest fees. ClawRouter uses the x402 Payment Required protocol for seamless micropayments. + + + Start with `blockrun/free` tier to test without payment, then upgrade to `blockrun/auto` for full model access. + + +### Spend Controls + +Set daily/monthly spending limits: + +```bash +# Set daily limit to $5 +clawrouter config set spendLimit.daily 5 + +# Set monthly limit to $50 +clawrouter config set spendLimit.monthly 50 +``` + +## Error Handling + +ClawRouter handles common LLM errors automatically at the router level: + +### Automatic Error Recovery + +| Error | Continue's Default | ClawRouter's Handling | +|-------|-------------------|----------------------| +| **429 Rate Limit** | Retry same provider with backoff | Route to different provider entirely | +| **402 Payment Required** | Fail immediately | x402 auto-payment from wallet | +| **500+ Server Error** | Retry same provider | Fallback to next model in tier | +| **Timeout** | Retry same provider | Route to faster model | + +### Response Headers + +ClawRouter adds diagnostic headers to every response: + +``` +x-clawrouter-model: anthropic/claude-sonnet-4.6 +x-clawrouter-tier: MEDIUM +x-clawrouter-cost: 0.0045 +x-clawrouter-fallback: false +``` + +When a fallback occurs: + +``` +x-clawrouter-model: openai/gpt-4o-mini +x-clawrouter-fallback: true +x-clawrouter-original-model: anthropic/claude-sonnet-4.6 +x-clawrouter-fallback-reason: 429_rate_limit +``` + +## Troubleshooting + +### Connection Refused + +If you see connection errors, make sure ClawRouter is running: + +```bash +# Check if ClawRouter is running +curl http://localhost:1337/v1/models + +# Start ClawRouter if needed +npx clawrouter +``` + +### Model Not Found + +If a specific model isn't available, check that ClawRouter has the required provider API keys configured. Run `clawrouter --help` for configuration options. + +### Slow Responses + +ClawRouter adds minimal latency (~10-50ms) for routing decisions. If responses are slow, the issue is likely with the upstream provider. Try a different model tier (`blockrun/eco` vs `blockrun/auto`). + +### AI-Powered Diagnostics + +Run the doctor command for AI-analyzed troubleshooting: + +```bash +# Basic diagnostics with Claude Sonnet (~$0.003) +npx clawrouter doctor + +# Complex issues with Claude Opus (~$0.01) +npx clawrouter doctor opus + +# Ask a specific question +npx clawrouter doctor "why are my requests failing?" +``` + +The doctor collects system info, wallet status, network connectivity, and sends to Claude for analysis. + +## Cost Monitoring + +ClawRouter provides cost tracking via response headers: + +- `x-clawrouter-cost` — Cost of the request +- `x-clawrouter-model` — Model that handled the request +- `x-clawrouter-complexity` — Computed complexity score + +You can view aggregated costs with: + +```bash +curl http://localhost:1337/stats +``` + +## Dual-Chain Wallet Support + +ClawRouter supports payments on two chains from a single wallet: + +| Chain | Token | Best For | +|-------|-------|----------| +| **Base (EVM)** | USDC | Lower fees, Coinbase integration | +| **Solana** | USDC | Fastest settlement | + +Switch chains via CLI: + +```bash +# Switch to Solana payments +clawrouter wallet solana + +# Switch to Base (EVM) payments +clawrouter wallet base + +# Check balances on both chains +clawrouter wallet +``` + +Both wallets are derived from the same BIP-39 mnemonic generated on first run. + +## Model Exclusion + +Block specific models from routing: + +```bash +# Block a model +clawrouter exclude add nvidia/gpt-oss-120b + +# Aliases work +clawrouter exclude add grok-4 + +# Show exclusions +clawrouter exclude + +# Remove exclusion +clawrouter exclude remove grok-4 +``` + +Useful when a model doesn't follow instructions well or you want to control costs. + +## Comparison with OpenRouter + +| Feature | ClawRouter | OpenRouter | +|---------|------------|------------| +| Hosting | Self-hosted (local) | Cloud-hosted | +| Automatic routing | ✅ Complexity-based | ❌ Manual selection | +| Cost optimization | ✅ 78-96% savings | ❌ Pay per model | +| Privacy | ✅ Data stays local | ⚠️ Data sent to cloud | +| Authentication | Wallet signature | API key | +| Payment | USDC (Solana/Base) | Credit card | +| Setup | `npx clawrouter` | Account signup | + + + ClawRouter can be used alongside OpenRouter — route complex tasks through ClawRouter while using OpenRouter for specific model access. + diff --git a/docs/customize/model-providers/overview.mdx b/docs/customize/model-providers/overview.mdx index fcd99be66..7ba030dcb 100644 --- a/docs/customize/model-providers/overview.mdx +++ b/docs/customize/model-providers/overview.mdx @@ -34,6 +34,7 @@ Beyond the top-level providers, Continue supports many other options: | [Together AI](/customize/model-providers/more/together) | Platform for running a variety of open models | | [DeepInfra](/customize/model-providers/more/deepinfra) | Hosting for various open source models | | [OpenRouter](/customize/model-providers/top-level/openrouter) | Gateway to multiple model providers | +| [ClawRouter](/customize/model-providers/more/clawrouter) | Open-source LLM router with automatic cost-optimized model selection | | [Tetrate Agent Router Service](/customize/model-providers/top-level/tetrate_agent_router_service) | Gateway with intelligent routing across multiple model providers | | [Cohere](/customize/model-providers/more/cohere) | Models specialized for semantic search and text generation | | [NVIDIA](/customize/model-providers/more/nvidia) | GPU-accelerated model hosting | diff --git a/docs/docs.json b/docs/docs.json index 13f482ea5..8556401ff 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -169,6 +169,7 @@ "group": "More Providers", "pages": [ "customize/model-providers/more/asksage", + "customize/model-providers/more/clawrouter", "customize/model-providers/more/deepseek", "customize/model-providers/more/deepinfra", "customize/model-providers/more/groq", diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 5bdee801d..6eb112821 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -216,6 +216,7 @@ "msty", "watsonx", "openrouter", + "clawrouter", "sambanova", "nvidia", "vllm", @@ -268,6 +269,7 @@ "### Msty\nMsty is the simplest way to get started with online or local LLMs on all desktop platforms - Windows, Mac, and Linux. No fussing around, one-click and you are up and running. To get started, follow these steps:\n1. Download from [Msty.app](https://msty.app/), open the application, and click 'Setup Local AI'.\n2. Go to the Local AI Module page and download a model of your choice.\n3. Once the model has finished downloading, you can start asking questions through Continue.\n> [Reference](https://continue.dev/docs/reference/Model%20Providers/Msty)", "### IBM watsonx\nwatsonx, developed by IBM, offers a variety of pre-trained AI foundation models that can be used for natural language processing (NLP), computer vision, and speech recognition tasks.", "### OpenRouter\nOpenRouter offers a single API to access almost any language model. To get started, obtain an API key from [their console](https://openrouter.ai/settings/keys).", + "### ClawRouter\nClawRouter is an open-source LLM router that automatically selects the cheapest capable model for each request based on prompt complexity, providing 78-96% cost savings. To get started, run `npx clawrouter` to start the router at localhost:1337. A wallet is auto-generated on first run - fund it with USDC (Solana/Base) to access premium models, or use `blockrun/free` tier without payment.\n> [Reference](https://github.com/BlockRunAI/ClawRouter)", "### SambaNova\n SambaNova provides fast inference of open-source language models with zero data retention. To get started, obtain an API key in [SambaNova Cloud](https://cloud.sambanova.ai/apis?utm_source=continue&utm_medium=external&utm_campaign=cloud_signup ).", "### NVIDIA NIMs\nNVIDIA offers a single API to access almost any language model. To find out more, visit the [LLM APIs Documentation](https://docs.api.nvidia.com/nim/reference/llm-apis).\nFor information specific to getting a key, please check out the [docs here](https://docs.nvidia.com/nim/large-language-models/latest/getting-started.html#option-1-from-api-catalog)", "### vLLM\nvLLM is a highly performant way of hosting LLMs for a team. To get started, follow their [quickstart](https://docs.vllm.ai/en/latest/getting_started/quickstart.html) to set up your server.", diff --git a/gui/public/logos/clawrouter.png b/gui/public/logos/clawrouter.png new file mode 100644 index 0000000000000000000000000000000000000000..b56a5cafbc540ce58fa6f17f0bb957740c9fd41d GIT binary patch literal 2362 zcmaKuc{~*O8^^yhlW}E`FiWg!DKV}rOPK5|<&1S~GnL7`zZl1iqZ~8NMkMVdLLoI1 zMUomhhcS+X%2hPYFgCezHtx0h|M&a7p4apF{P8@0ykDQcJ{hN7?4=}>Bme+Xr%qzr z_nh*5#o&9&w!YA_XK-Ifdkon9J|#^I8USJor!XfxVvFXv&z61U52wf~yi+OD6vB#b{#Cb#hVr#2h6J`($_ z){awTY{k@5|BIkRCSza(2SV3KN5_nXZb>v0i<~j$)PGuN{=`A1xig**|0eGpHu;Ir zAdiJYE|aaAbN#1{wtGk^2$(%@qD2Sx=KeG*#<+a zzZ^~L=@HB@)V^YU^wEn$Gc4X$H}p%=qA?HU2~Ll=|c z5pzL0pAc1z5n&lp{M72|dq}Bnuo8Jzyyzn*Xro4P=q62BUjzl_r{7gNHFkCk9)a#) z<)S&qcE|DLiLBY)m-j=tOWK~vanZO?e`KYtHqIcrxWJn#@`nN41tj!!_a zuIRaNdyEqL`7b`J8*DB+Nk0;@H819`{t8V0C~#blXf{|fW$5qI1?8j&6)~K?(-FC9 z>pbVxOT!-Wr2Cor1+ix69zCa{aFfKD=R&rKtv~ETwWavP)IsSSuBJJFR+4*4! z45)3hzb4u_7%hzx7xT>-4LOb-*KWw2h}LN?o}9T+A9+qMFraU|()+FkO5bq1YNZPw z#!j?sN^@=w>udI>lc*GFpAbFB$cIXSImk3-OgWWo!=PUQ>0Ia;TtV@xo7(y1_~j@w z2>IDq(7KGAd@;n2%ds;+Nm-=m0g zx57#L4c)xY!h)1}2ecEau+Nhz@`WmM##OaAwi}@SnL*pQHGASr99jGq!HA=fS@z5o zlImu^lD1GJf*v4%yJsICuGsrr9#i&#tdHf$q}~!-Pud6>xaHwJed%!Xog^=jnuEH% z^=Jou*t3mpwQ(hHmwnC);)_?g8|9?wwbpuLbqi>O?jP&+P??AW6eT`KVHadS}abisrr4b<9JiG7dNG$;YHTbw=4ibu8kN1REl=lV^;(jJ2M9b=|F^^~@7FUDs17_fyqaw9$ zJJjRe()_tkDC^s(P^~sLoPG4N-GhKHibTnuar<*U=yi&$AgT1Py+Lx!_vPa=D^Pfh z>HAU1c8_VP&}ftzU0ZMmBnC5F^3Oh>>Cyu|*Whx9(MmaLN`*Be zzf1|lLjj;|&S?S!F2BZ5wJeWz+jdA5C&(2#P0JOm{{(*x>y2IQ4b5N{4N84f{H5Dz z8UIVR>Kb&6IPg71SOYvSn%}KU>nTR+HmfEA|Fao z^(xoo=*uQGs~GM6$e18!LBOl-Sq>DMlEsWe<|jBOyPalZcijqbpfbuydvmC = { ...options, baseURL: options.baseURL ?? "https://openrouter.ai/api/v1/", }), + clawrouter: (options) => + createOpenAI({ + ...options, + baseURL: options.baseURL ?? "http://localhost:1337/v1/", + }), }; export class AiSdkApi implements BaseLlmApi { diff --git a/packages/openai-adapters/src/apis/ClawRouter.test.ts b/packages/openai-adapters/src/apis/ClawRouter.test.ts new file mode 100644 index 000000000..b90796103 --- /dev/null +++ b/packages/openai-adapters/src/apis/ClawRouter.test.ts @@ -0,0 +1,42 @@ +import { describe, expect, it } from "vitest"; + +import { ClawRouterApi } from "./ClawRouter.js"; + +describe("ClawRouterApi", () => { + const baseConfig = { + provider: "clawrouter" as const, + }; + + it("should use default apiBase when not provided", () => { + const api = new ClawRouterApi(baseConfig); + expect(api["config"].apiBase).toBe("http://localhost:1337/v1/"); + }); + + it("should allow custom apiBase", () => { + const api = new ClawRouterApi({ + ...baseConfig, + apiBase: "http://custom:8080/v1/", + }); + expect(api["config"].apiBase).toBe("http://custom:8080/v1/"); + }); + + it("should include Continue headers", () => { + const api = new ClawRouterApi(baseConfig); + const headers = api["getHeaders"](); + + expect(headers["User-Agent"]).toBe("Continue/IDE"); + expect(headers["X-Continue-Provider"]).toBe("clawrouter"); + }); + + it("should include standard OpenAI headers", () => { + const api = new ClawRouterApi({ + ...baseConfig, + apiKey: "test-key", + }); + const headers = api["getHeaders"](); + + expect(headers["Content-Type"]).toBe("application/json"); + expect(headers["Accept"]).toBe("application/json"); + expect(headers["Authorization"]).toBe("Bearer test-key"); + }); +}); diff --git a/packages/openai-adapters/src/apis/ClawRouter.ts b/packages/openai-adapters/src/apis/ClawRouter.ts new file mode 100644 index 000000000..15f334eb2 --- /dev/null +++ b/packages/openai-adapters/src/apis/ClawRouter.ts @@ -0,0 +1,42 @@ +import { OpenAIApi } from "./OpenAI.js"; +import { OpenAIConfig } from "../types.js"; + +export interface ClawRouterConfig extends OpenAIConfig {} + +/** + * ClawRouter API adapter + * + * ClawRouter is an open-source LLM router that automatically selects the + * cheapest capable model for each request based on prompt complexity, + * providing 78-96% cost savings on blended inference costs. + * + * Features: + * - 15-dimension prompt complexity scoring + * - Automatic model selection (cheap → capable based on task) + * - OpenAI-compatible API at localhost:1337 + * - Support for multiple routing tiers (auto, free, eco) + * + * @see https://github.com/BlockRunAI/ClawRouter + */ +export class ClawRouterApi extends OpenAIApi { + constructor(config: ClawRouterConfig) { + super({ + ...config, + apiBase: config.apiBase ?? "http://localhost:1337/v1/", + }); + } + + /** + * Override headers to include Continue-specific User-Agent + * This helps ClawRouter track integration usage and optimize accordingly + */ + protected override getHeaders(): Record { + return { + ...super.getHeaders(), + "User-Agent": "Continue/IDE", + "X-Continue-Provider": "clawrouter", + }; + } +} + +export default ClawRouterApi; diff --git a/packages/openai-adapters/src/index.ts b/packages/openai-adapters/src/index.ts index 43af4e81b..467c7a71a 100644 --- a/packages/openai-adapters/src/index.ts +++ b/packages/openai-adapters/src/index.ts @@ -18,6 +18,7 @@ import { MockApi } from "./apis/Mock.js"; import { MoonshotApi } from "./apis/Moonshot.js"; import { OpenAIApi } from "./apis/OpenAI.js"; import { OpenRouterApi } from "./apis/OpenRouter.js"; +import { ClawRouterApi } from "./apis/ClawRouter.js"; import { RelaceApi } from "./apis/Relace.js"; import { VertexAIApi } from "./apis/VertexAI.js"; import { WatsonXApi } from "./apis/WatsonX.js"; @@ -179,6 +180,8 @@ export function constructLlmApi(config: LLMConfig): BaseLlmApi | undefined { return openAICompatible("https://api.tensorix.ai/v1/", config); case "openrouter": return new OpenRouterApi(config); + case "clawrouter": + return new ClawRouterApi(config); case "llama.cpp": case "llamafile": return openAICompatible("http://localhost:8000/", config); diff --git a/packages/openai-adapters/src/types.ts b/packages/openai-adapters/src/types.ts index 900ce7af8..3b324b0ac 100644 --- a/packages/openai-adapters/src/types.ts +++ b/packages/openai-adapters/src/types.ts @@ -52,6 +52,7 @@ export const OpenAIConfigSchema = BasePlusConfig.extend({ z.literal("kindo"), z.literal("msty"), z.literal("openrouter"), + z.literal("clawrouter"), z.literal("sambanova"), z.literal("text-gen-webui"), z.literal("vllm"),