🤖 AI Tools
· 4 min read

How to Use DeepSeek V4 on OpenRouter: Setup and Configuration Guide (2026)


DeepSeek V4 is one of the strongest open-weight model families available in 2026. Running it through OpenRouter gives you a single API key that works with V4 Pro, V4 Flash, and 300+ other models from OpenAI, Anthropic, Google, and more. This guide walks through setup, model IDs, pricing, coding tool integration, and fallback routing.

Why Use DeepSeek V4 Through OpenRouter

Accessing DeepSeek V4 directly through the DeepSeek API works fine, but OpenRouter adds several practical advantages:

  • One API key for everything. Switch between DeepSeek V4 Pro, V4 Flash, Claude, GPT, Gemini, and Kimi K2.6 without managing separate accounts.
  • Fallback routing. If one provider goes down or hits rate limits, OpenRouter can automatically route your request to a backup model.
  • Unified billing. One dashboard, one invoice, one credit balance across all models.
  • Provider diversity. OpenRouter aggregates multiple hosting providers for the same model, improving uptime and reducing latency by picking the fastest available endpoint.
  • OpenAI-compatible API. Drop-in replacement for any tool or library that supports the OpenAI chat completions format.

If you already use OpenRouter for other models, adding V4 takes about 30 seconds.

DeepSeek V4 Model IDs on OpenRouter

OpenRouter uses namespaced model IDs. Here are the expected identifiers for the V4 family:

ModelOpenRouter IDContext WindowBest For
DeepSeek V4 Prodeepseek/deepseek-v4-pro128K tokensComplex reasoning, long-context coding, research
DeepSeek V4 Flashdeepseek/deepseek-v4-flash64K tokensFast inference, chat, lightweight coding tasks

Model IDs may update after launch. Check the OpenRouter models page for the latest identifiers.

Setup: API Key and First Request

Step 1: Get Your OpenRouter API Key

  1. Create an account at openrouter.ai.
  2. Navigate to Keys in your dashboard.
  3. Click Create Key and copy the value. Store it securely.

Step 2: Set Your Environment Variable

export OPENROUTER_API_KEY="sk-or-v1-your-key-here"

Step 3: Make a Request with Python

OpenRouter uses the same format as the OpenAI API. You can use the openai Python package directly:

from openai import OpenAI

client = OpenAI(
    base_url="https://openrouter.ai/api/v1",
    api_key="sk-or-v1-your-key-here",
)

response = client.chat.completions.create(
    model="deepseek/deepseek-v4-pro",
    messages=[
        {"role": "user", "content": "Explain Python generators in 3 sentences."}
    ],
)

print(response.choices[0].message.content)

To use V4 Flash instead, swap the model ID to deepseek/deepseek-v4-flash. Everything else stays the same.

cURL Example

curl https://openrouter.ai/api/v1/chat/completions \
  -H "Authorization: Bearer $OPENROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek/deepseek-v4-pro",
    "messages": [
      {"role": "user", "content": "Write a Rust function to reverse a string."}
    ]
  }'

Pricing: OpenRouter vs Direct DeepSeek API

OpenRouter adds a small markup on top of provider pricing. Here is an approximate comparison:

ModelDirect DeepSeek (Input / Output per 1M tokens)OpenRouter (Input / Output per 1M tokens)Markup
V4 Pro~$2.00 / ~$8.00~$2.20 / ~$8.80~10%
V4 Flash~$0.50 / ~$2.00~$0.55 / ~$2.20~10%

The markup pays for unified routing, fallback logic, and provider aggregation. For most users, the convenience outweighs the cost difference. Check the OpenRouter pricing page for live rates, as these fluctuate.

Using DeepSeek V4 with Coding Tools

Aider

Aider supports OpenRouter natively. Set the base URL and model:

export OPENAI_API_BASE=https://openrouter.ai/api/v1
export OPENAI_API_KEY=sk-or-v1-your-key-here

aider --model openrouter/deepseek/deepseek-v4-pro

For faster iteration on smaller edits, use V4 Flash:

aider --model openrouter/deepseek/deepseek-v4-flash

Continue.dev

Add this to your Continue configuration file (~/.continue/config.json):

{
  "models": [
    {
      "title": "DeepSeek V4 Pro (OpenRouter)",
      "provider": "openrouter",
      "model": "deepseek/deepseek-v4-pro",
      "apiKey": "sk-or-v1-your-key-here"
    }
  ]
}

OpenCode

Set the environment variables and point OpenCode at the OpenRouter endpoint:

export OPENAI_API_BASE=https://openrouter.ai/api/v1
export OPENAI_API_KEY=sk-or-v1-your-key-here

opencode --model deepseek/deepseek-v4-pro

Fallback Configuration: V4 Flash Primary, V4 Pro Backup

One of OpenRouter’s best features is route-level fallback. You can set V4 Flash as your primary model for speed and cost, then fall back to V4 Pro when the task is complex or Flash is unavailable.

Send this in your request body:

{
  "model": "deepseek/deepseek-v4-flash",
  "route": "fallback",
  "models": [
    "deepseek/deepseek-v4-flash",
    "deepseek/deepseek-v4-pro"
  ],
  "messages": [
    {"role": "user", "content": "Refactor this module to use dependency injection."}
  ]
}

OpenRouter will try V4 Flash first. If it fails (rate limit, timeout, provider outage), the request automatically retries with V4 Pro. You can also mix in models from other providers:

"models": [
  "deepseek/deepseek-v4-flash",
  "deepseek/deepseek-v4-pro",
  "anthropic/claude-sonnet-4"
]

This gives you a three-tier fallback chain across two completely different model providers.

FAQ

Is my data private when using DeepSeek V4 through OpenRouter?

OpenRouter acts as a proxy. Your prompts are forwarded to the underlying provider hosting the model. Review both OpenRouter’s and DeepSeek’s privacy policies. For sensitive workloads, consider self-hosting V4 since it is open-weight.

Can I use OpenRouter’s free tier with DeepSeek V4?

OpenRouter occasionally offers free credits for new accounts and may provide free access to select models. V4 Flash is more likely to appear on free tiers than V4 Pro due to lower compute costs. Check the OpenRouter dashboard for current free model availability.

How does latency compare to the direct DeepSeek API?

OpenRouter adds a small routing overhead, typically 50 to 200ms on the first token. For streaming responses, the difference is negligible after the initial token. If you need the absolute lowest latency, the direct API will be marginally faster, but OpenRouter’s provider aggregation can sometimes find a faster endpoint than the default.

Wrapping Up

Running DeepSeek V4 Pro and V4 Flash through OpenRouter is the most flexible way to access these models. You get unified billing, fallback routing, and compatibility with tools like Aider out of the box. The setup takes minutes, and switching between V4 and any other model on the platform is a one-line change.