Skip to content
| Marketplace
Sign in
Visual Studio Code>AI>OpenRouter Anthropic Models — Cost-OptimizedNew to Visual Studio Code? Get it now.
OpenRouter Anthropic Models — Cost-Optimized

OpenRouter Anthropic Models — Cost-Optimized

monolog

| (0) | Free
Opus, Sonnet, and Haiku in VS Code Copilot — powered by OpenRouter with Anthropic prompt caching.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Anthropic Claude in VS Code Copilot

Use Claude Opus 4.8, Claude Sonnet 4.6, and Claude Haiku 4.5 in VS Code Copilot Chat — powered by OpenRouter with Anthropic prompt caching.

Features

✨ Three Anthropic models in Copilot Chat:

  • Claude Opus 4.8 — Most capable, best for complex reasoning and analysis
  • Claude Sonnet 4.6 — Fast and balanced, excellent for coding and general tasks
  • Claude Haiku 4.5 — Ultra-fast and efficient, perfect for quick tasks and high-volume work

🚀 Anthropic prompt caching built-in:

  • ~90% savings on repeat context in multi-turn sessions via Anthropic's native prompt caching
  • Provider pinning — locks requests to Anthropic-direct so caches accumulate and reuse across turns
  • Frontier models only — optimized for the latest Anthropic Claude family (Opus 4.8, Sonnet 4.6, Haiku 4.5)
  • Fully tunable — adjust caching and routing via VS Code settings without rebuilding

Quick Setup (60 seconds)

1. Get an API key

Visit https://openrouter.ai/keys (free sign-up)

2. Set it in VS Code

Option A (Easiest): Environment variable

# Windows PowerShell (add to profile)
$env:OPENROUTER_API_KEY = "sk-or-..."

Option B: VS Code command Ctrl+Shift+P → "OpenRouter: Set API Key" → paste your sk-or-... key → reload window

The extension checks the environment variable first, then falls back to the stored key.

3. Start coding

Pick an OpenRouter model in Copilot Chat and ask away!

Configuration

All settings are optional — sensible defaults work out of the box:

Setting Default Description
vscode-openrouter.enablePromptCaching true Use Anthropic cache_control on stable prefix (saves 90% on cache hits)
vscode-openrouter.providerOrder ["anthropic"] Pin anthropic/* models to Anthropic-direct so caches reuse
vscode-openrouter.allowFallbacks true Fall back to other providers if primary is down (costs full price that turn)

Press Ctrl+, and search openrouter to adjust.

How It Works

  1. This extension registers a custom VS Code Language Model Chat Provider
  2. When you pick an OpenRouter model, your message is sent to openrouter.ai/api/v1/chat/completions
  3. Your API key is stored securely in the OS credential store (Windows Credential Manager, macOS Keychain, etc.)
  4. Anthropic prompt caching is enabled — the system instructions + tools block is cached on the first turn, then reused at ~90% discount on subsequent turns

Commands

Command Description
OpenRouter: Set API Key Store your API key securely
OpenRouter: Clear API Key Remove the stored key

Troubleshooting

"No API key configured"

  • Run Ctrl+Shift+P → OpenRouter: Set API Key and paste your key from https://openrouter.ai/keys

"401 Unauthorized"

  • Your API key is invalid or expired
  • Check https://openrouter.ai/keys to confirm it's active
  • Re-run OpenRouter: Set API Key with the correct key

Models not appearing

  • Reload: Ctrl+Shift+P → Developer: Reload Window

Slow responses

  • Check OpenRouter status
  • Try a different model to isolate the issue

System Requirements

  • VS Code 1.90.0 or later
  • OpenRouter API key (free at https://openrouter.ai)

License

MIT

npm run compile
npm run package
code --install-extension vscode-openrouter-1.0.0.vsix

Reload VS Code after reinstalling.

Architecture

  • Entry point: src/extension.ts
  • API key storage: context.secrets (VS Code Secret Storage → OS Credential Manager)
  • Provider registration: vscode.lm.registerLanguageModelChatProvider('openrouter', provider) on activation
  • Streaming: Node https module, parses SSE data: lines, emits LanguageModelTextPart and LanguageModelToolCallPart via progress.report()
  • Message conversion: toOpenAIMessages() converts VS Code's LanguageModelChatRequestMessage format (including ToolCallPart / ToolResultPart) to OpenAI-compatible message array
  • Minimum VS Code version: 1.90.0
  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft