Back to blog

Optimizing AI Agent Costs: Running Claude Code on DeepSeek and Qwen

Learn how to point the Claude Code CLI to alternative LLMs via compatible endpoints to cut engineering token costs while keeping team productivity high.

Oct 11, 2026
7
directions
notes from delivery practice
3
levels
strategy · process · tools
1
library
guides · checklists · cases
See cases

Model Flexibility in Modern AI-Assisted Engineering

Autonomous coding agents are rapidly reshaping everyday software development. Anthropic's Claude Code has emerged as an exceptionally capable terminal agent for repository navigation, complex refactoring, and code generation. However, rolling out agentic workflows across an entire development team can quickly drive API costs upward when tied exclusively to flagship proprietary endpoints.

Because Claude Code communicates with its backend via the Anthropic Messages format, any endpoint or proxy that supports this interface can act as a drop-in replacement. This enables engineering leaders to decouple the agent CLI from a single model provider and route execution to cost-efficient alternatives such as DeepSeek-V3 or Qwen.

Connecting Alternative LLMs to Claude Code

Switching the underlying intelligence of the agent requires nothing more than adjusting environment variables or the tool's local configuration:

  • ANTHROPIC_BASE_URL: The custom gateway URL pointing to your API provider without trailing version paths.
  • ANTHROPIC_AUTH_TOKEN: The API key for your chosen gateway, transmitted using Bearer authentication.
  • ANTHROPIC_MODEL: The primary model identifier destined to handle code generation and reasoning.
  • ANTHROPIC_DEFAULT_HAIKU_MODEL: The secondary model assigned to lightweight background tasks.

The secondary model configuration is crucial. The agent offloads smaller internal checks to a fast-tier model. If this secondary variable continues pointing to an unsupported Anthropic identifier, background routines fail silently, leading to degraded agent performance during multi-step tasks.

Prompt Caching and Context Optimization

Agentic tools inherently transmit heavy system contexts, including project structures, linters, and operational rules, on every call. Claude Code injects extensive system instructions with each interaction. Consequently, choosing an API provider that supports prompt caching is essential for real-world cost containment.

With prompt caching active, the initial request writes the system prompt to the cache, allowing subsequent tool invocations in the session to read the context at a fraction of standard input pricing. Combined with the already competitive pricing of open-weights models like DeepSeek or Qwen, total operational expenses drop dramatically during deep coding sessions.

Teams should also note context window enforcement. When Claude Code detects an unrecognized model string, it falls back to defensive context compaction routines. Engineering teams can override this behavior through dedicated configuration flags to leverage the full context window offered by modern foundation models.

Strategic Value for Engineering Teams

Separating the developer interface from the underlying model provider delivers tangible operational advantages:

  • Direct Cost Optimization: Run everyday code maintenance on cost-effective models while reserving premium frontier models for high-complexity architectural design.
  • Vendor Independence: Avoid hard lock-in by maintaining an infrastructure setup capable of switching providers via simple environment updates.
  • Self-Hosting Readiness: Route agent requests through internally hosted open-weights models when strict data privacy standards are required.

At ViAcore, we focus on building robust engineering processes that combine cutting-edge AI capabilities with sustainable infrastructure economics.

Services on this topic

Need this for your project?

Development turnkey: analysis → implementation → launch → support. Tell us about your task — we will reply with an estimate.

About the direction

Relevant articles