# DeepSeek API for coding agents: direct integration vs Weave Router

Canonical: https://weaveos.com/blog/deepseek-api-coding-agents-weave-router

Published: 2026-11-03T08:00:00.000Z

Updated: 2026-11-13T00:00:00.000Z

By Sammy Tourani

**Weave Router uses DeepSeek alongside other enabled models and selects a model for each coding request.** It accounts for cache costs and can escalate when work stalls. Your engineers keep their coding client, administrators control the model pool, and an explicit model pin remains available when the task needs it.

Direct DeepSeek access is the path when you specifically want a DeepSeek model and its API billing. This guide covers that setup, then shows where Weave’s model selection, client controls and session-level cost records change the workflow.

API details and prices checked November 13, 2026.

## Send a direct DeepSeek API request

DeepSeek's [official quickstart](https://api-docs.deepseek.com/) uses `https://api.deepseek.com` for OpenAI-format requests. Its current API model IDs are `deepseek-flash` and `deepseek-v4-pro`.

With your DeepSeek API key already set in `DEEPSEEK_API_KEY`, this Bash example requests a small Python change:

```bash
curl --fail-with-body --silent --show-error \
  'https://api.deepseek.com/chat/completions' \
  -H "Authorization: Bearer ${DEEPSEEK_API_KEY}" \
  -H 'Content-Type: application/json' \
  --data-binary @- <<'JSON'
{
  "model": "deepseek-flash",
  "messages": [
    {
      "role": "user",
      "content": "Write a Python mean(values) function that returns 0 for an empty list. Include two unit tests."
    }
  ],
  "thinking": { "type": "enabled" },
  "reasoning_effort": "high",
  "stream": false
}
JSON
```

Read the generated answer in `choices[0].message.content`. This request returns suggested code. A coding agent also needs to apply edits, execute tools, and run tests in your repository.

For a custom tool loop, follow DeepSeek's [Chat Completions contract](https://api-docs.deepseek.com/api/create-chat-completion/) and [thinking-mode guide](https://api-docs.deepseek.com/guides/thinking_mode/). Thinking mode is enabled by default. It rejects `required` and named `tool_choice` values, and requests that carry tools must retain the required `reasoning_content` in later messages. A successful text-only request does not exercise that tool loop.

## Connect Claude Code or Codex

Both paths work with Claude Code and Codex. Direct setup sends requests to a DeepSeek model; Weave setup lets its policy select among the models and providers your organization enables.

| Coding agent | Direct DeepSeek setup | Weave Router setup |
| --- | --- | --- |
| Claude Code | [DeepSeek's Claude Code guide](https://api-docs.deepseek.com/quick_start/agent_integrations/claude_code/) uses its Anthropic-compatible endpoint and a DeepSeek key | `npx @weave-os/router --claude` configures the client for Weave |
| Codex | [DeepSeek's Codex guide](https://api-docs.deepseek.com/quick_start/agent_integrations/codex/) uses its native Responses API and a DeepSeek model catalog | `npx @weave-os/router --codex` configures the client for Weave |

DeepSeek's Claude Code guide also documents model-name mapping. Claude Opus names select DeepSeek Pro; Claude Haiku and Sonnet names select DeepSeek Flash. Check the served model when comparing costs.

Weave's [managed setup guide](https://docs.weaveos.com/router/getting-started) requires Node.js 18 or later, an organization-issued router key, and the credits, subscriptions, or provider keys appropriate to your plan. The installer handles the coding client's configuration. Self-hosting is a separate deployment path in the [Router README](https://github.com/weave-os/router/blob/b1f70281bdca136edf61b049b9880de655d13379/README.md#run-it-yourself).

Keep the credentials distinct. A DeepSeek key authenticates to DeepSeek. A Weave router key authenticates to Weave. For routed DeepSeek models, confirm the enabled model and its upstream provider in your Router configuration. The [provider reference](https://github.com/weave-os/router/blob/b1f70281bdca136edf61b049b9880de655d13379/docs/CONFIGURATION.md) documents OpenRouter and other OpenAI-compatible endpoints; the [custom-endpoint guide](https://docs.weaveos.com/router/custom-endpoints) explains provider bindings and model aliases.

## What Weave adds over direct DeepSeek access

A coding session contains many model requests. Reading a file, interpreting a tool result, proposing a patch, and responding to a failed test can each lead to another request with a different amount of work to do.

Weave's [routing semantics](https://github.com/weave-os/router/blob/b1f70281bdca136edf61b049b9880de655d13379/docs/SEMANTICS.md) define an **action** as one upstream API request to a model. That is the routing grain. One agent turn can contain several actions. Session state and explicit model pins can influence each decision; per-action routing does not mean switching models on every request.

With Weave, DeepSeek can be one option in the model pool rather than the fixed choice for every request:

- **Keep DeepSeek available without locking every task to it.** Include the DeepSeek routes your organization enables alongside other models, while engineers keep the same coding client.
- **Keep control of the model pool.** Use Weave's [routing controls](https://docs.weaveos.com/router/models-and-routing) to exclude models or providers, set preferences and pin a session. Automatic selection works within those choices.
- **See what each coding session used and cost.** [Router reporting](https://docs.weaveos.com/router/reporting) connects requests to models, tokens, costs, users and sessions. Export the calls when finance needs to reconcile the model mix with spending.

The agent executes local tools. Router selects the upstream model. For example, a request that produces a file-read tool call and the next request carrying that file's contents are separate routing actions, even though they belong to the same task.

### Change models without making engineers manage every turn

A session may start with routine file exploration and later reach a difficult debugging step. Weave can use a cheaper model where the policy expects it to handle the work, then escalate if the agent stalls or misses instructions. It considers the cost of rebuilding the prompt cache before switching.

### Keep usage records across the model mix

When more than one model serves a session, the total matters more than the price of any single call. Weave records serving models, tokens and costs so the team can inspect where a session became expensive. Its exports distinguish API-rate usage from the amount charged, including eligible subscription-covered requests. You can compare model choices without losing the cost of escalation, retries or cached context.

## Direct API access vs routed access

| Decision | Direct DeepSeek API | Weave Router |
| --- | --- | --- |
| Model selection | Your client sends a DeepSeek model ID | Router chooses among enabled provider/model bindings; you can also request a pin |
| API connection | DeepSeek documents Chat Completions, Anthropic-compatible Messages, and Responses | Use Weave's supported client setup or documented ingress for your deployment |
| Tools, streaming, and images | Follow DeepSeek's request and reasoning contracts; its [current model table](https://api-docs.deepseek.com/quick_start/pricing/) lists vision for Flash, while Pro does not support it | Test the same tool loop and image inputs through the selected client, model, and provider |
| Caching | DeepSeek's cache-hit rules and direct rates apply | Cache behavior and charges follow the selected upstream and routing configuration |
| Cost accounting | DeepSeek API usage and tool charges | Your Weave plan, provider usage, and any connected subscription or BYOK terms |
| Operational view | Collect usage through your DeepSeek integration | Central model/provider controls, request costs, session drilldowns, and decision exports |

DeepSeek API model IDs and Router catalog IDs are different namespaces. Record the exact served model and provider on both paths before treating two runs as a model-for-model comparison.

## DeepSeek API pricing

These are DeepSeek's published direct API rates, checked November 13, 2026. All values are **USD per one million tokens**, shown as **off-peak / peak**. The [official pricing page](https://api-docs.deepseek.com/quick_start/pricing/) is the source of truth.

| API model | Cached input | Uncached input | Output |
| --- | --- | --- | --- |
| `deepseek-flash` | $0.003 / $0.006 | $0.15 / $0.30 | $0.60 / $1.20 |
| `deepseek-v4-pro` | $0.022 / $0.044 | $0.66 / $1.32 | $1.98 / $3.96 |

Peak windows are 01:00-04:00 and 06:00-10:00 UTC, Monday through Friday, excluding Chinese public holidays. The current `deepseek-flash` alias serves DeepSeek-V4.1-Flash-1017; the Pro version is DeepSeek-V4-Pro-0813. DeepSeek also lists Search and Fetch separately at $0.75 per 1,000 successful requests for each API. Include those charges when your agent uses those services.

Your effective cost depends on input/output mix, cache hits, reasoning, retries, and tool loops. [DeepSeek caching](https://api-docs.deepseek.com/guides/kv_cache/) is enabled by default, but hits depend on matching persisted prefixes. Use returned usage rather than assuming the whole repository context is cached.

These direct rates are not a Weave invoice estimate. Use the actual upstream and [Weave billing terms](https://docs.weaveos.com/router/billing) for your selected path. Keep the estimate date with your budget because provider rates and model aliases change.

## Weave's published cost and quality evidence

Weave's [Router 2.0 evaluation](/blog/introducing-weave-router-2-0) reports about half the cost per trial and more than twice the speed on two agentic coding benchmarks, with solve rates of 62.1% versus Astra's 60.6% on Terminal-Bench and 62.1% versus 66.1% on SWE-Atlas. Router and GPT-6 Astra used the same Codex harness and tasks, with two attempts per task in paired runs.

| Benchmark | Tasks | Router / Astra tasks solved | Router / Astra cost per trial | Router / Astra mean time per trial |
| --- | --- | --- | --- | --- |
| Terminal-Bench 4.0 | 66 | 62.1% / 60.6% | $5.22 / $10.03 | 20.5 / 44.1 minutes |
| SWE-Atlas Codebase QnA | 124 | 62.1% / 66.1% | $2.31 / $5.04 | 6.8 / 16.7 minutes |

Tasks solved is pass@2: a task counts when either attempt passes. Cost and time are per trial. The published comparison is Router versus GPT-6 Astra; it does not establish the result of a direct DeepSeek comparison.

Customer results are separate from this benchmark: Weave reports average token-spend savings of 40% with Router. Its [July 2026 customer update](https://weaveos.com/blog/weave-raises-13.5m-series-a-to-build-engineering-and-token-intelligence) reported Router cost cuts of **20–80%**. The paired benchmark measures task completion, cost and duration, including unsuccessful attempts. Those measures help you evaluate routing beyond the listed price of an individual model call. The [published methodology](/router/benchmark-methodology) makes the comparison inspectable.

## Compare the two paths on your repository

Start with direct DeepSeek as an explicit baseline, then compare it with Weave Router using the same coding agent, task mix, acceptance tests, and review standard. Record the exact model versions and reasoning settings. Include failed attempts and retries in both groups.

| Measure | What to record |
| --- | --- |
| API spend | Input/output usage, cache hits, tool charges, retries, and the actual billed cost |
| Task completion | Whether the requested change passes the same acceptance criteria |
| Latency | Time to first token and time to a completed, accepted change |
| Code quality | Review findings, post-merge defects, and follow-up work |
| PR keep rate | The same retention definition and follow-up window for both groups |
| Cost per merged PR | Total spend on all attempts divided by merged PRs in the tested work |

Use Router's serving-model and session records to inspect its choices, then connect those sessions to your work items. Its dashboard's savings comparison uses the configured comparison model; a direct DeepSeek pilot needs a matched direct baseline as well.

Keep API-rate usage and the amount charged separate. [Weave’s per-call export](https://github.com/weave-os/router/blob/b1f70281bdca136edf61b049b9880de655d13379/docs/ANALYTICS_EXPORT.md) reports both: included subscription turns retain their real tokens and API-rate equivalent while actual API spend is zero. Use API-rate fields for a model-usage comparison, actual-cost fields for billed inference, and add plan and subscription fees when comparing total budgets. The raw export does not supply a precomputed counterfactual savings figure.

## Diagnose a slow or failed routed request

For a direct DeepSeek connection, your client and provider logs describe that API path. Weave's [call-level export](https://docs.weaveos.com/router/analytics-export) adds the routing decision: the model requested, the one served, its provider, failover and policy identifiers. Routing latency, upstream latency and time to first token are separate fields, so a delay can be investigated at the relevant stage rather than attributed to the model by default.

Upstream HTTP status, finish reason and invalid tool-argument counts help explain requests that returned but did not complete the agent's next step. The export is one row per model call; retries must be grouped by request ID to avoid treating several attempts as independent completed requests. Model and provider controls remain available when a repository task needs a deliberate choice instead of automatic routing.

## Set up Weave Router

Weave handles model selection while DeepSeek remains available in the enabled pool. [Code Max](/products/router/max) provides automatic open-model selection free for the first month with $10 in credits for $50 in usage, then costs $10/month. Engineers keep their coding clients, and administrators retain provider controls and session-level reporting. Direct DeepSeek remains a separate API path with its own billing.

**[Set up Weave Router](/router/quickstart)** and compare the resulting model mix, spend, and completed work with your direct baseline.

## Frequently asked questions

### Can Claude Code and Codex use DeepSeek directly?

Yes. DeepSeek publishes client-specific guides for Claude Code through its Anthropic-compatible endpoint and Codex through its Responses API. Use the current guide for your client rather than reusing another client's configuration.

### Can Weave select a different model within one agent turn?

Yes. Weave makes a routing decision for each upstream API request, and an agent turn can contain several requests. Session state, model pins and the deployment policy determine whether the selected model changes.

### Does Weave Router provide DeepSeek's official API?

They are separate services. DeepSeek operates its direct API. Weave Router selects models and providers for supported agent requests, including enabled DeepSeek routes in your configuration.

### Can I compare DeepSeek's token rate with Router's benchmark cost?

They measure different things. The pricing table is USD per million direct API tokens. The benchmark reports cost per trial on a stated task set. Compare both paths using the same tasks and include all attempts before drawing a cost conclusion.
