417 Million Tokens for Just USD 5.01: My DeepSeek + Codex Experience in VS Code — What Can I Improve to Optimize AI Coding Costs Further?
DEV Community

417 Million Tokens for Just USD 5.01: My DeepSeek + Codex Experience in VS Code - What Can I Improve to Optimize AI Coding Costs Further?

Build. Measure. Learn. Improve. Repeat.

I have been experimenting with AI-assisted software development for a while. One thing I keep learning is that getting an AI coding agent to produce code is only part of the job.

We also need to understand how it uses context, how often it calls the model, how much data it sends, and - of course - how much all of that costs.

During one experiment, I configured DeepSeek as the model provider for the Codex IDE extension in Visual Studio Code and used it in my development workflow. When I reviewed the billing data, I found something interesting: 417,153,568 billed tokens for approximately USD 5.01.

That result made me curious. But I do not see it as proof that I have found the perfect cost-optimization method. Instead, I see it as a starting point.

What does the number actually mean? Where did the money go? Is a high cache-hit rate enough to make an AI coding workflow efficient? And what should I improve next? This is what I want to share.

My Setup: DeepSeek + Codex + VS Code

I configured DeepSeek as the model provider for the Codex IDE extension in Visual Studio Code. The development environment remained on my workstation.

VS Code, the Codex extension, the project workspace and local tool interactions were handled locally. Model inference and API billing took place through DeepSeek's remote API.

This distinction is important: using a local IDE with a remote model provider does not mean that the model itself is running locally or offline.

Here is a screenshot from my development environment during the experiment.

Figure 1. My VS Code environment with the Codex extension and a DeepSeek model selected. This documents the visible development setup, but it does not independently prove that every request in the billing report came from this interface.

For developers who want to try a similar setup, start with the official documentation: DeepSeek - Integrate with Codex, DeepSeek API Documentation.

Model names, API endpoints, supported protocols, authentication flows and pricing can change. Check the current documentation before configuring your own environment.

The Result: 417 Million Billed Tokens for USD 5.01

The following screenshot is from my DeepSeek Platform usage dashboard.

Figure 2. DeepSeek Platform usage dashboard. The visible summary shows USD 5.01, 962 API requests and 417,153,568 tokens.

I reviewed the exported billing records for the period 29 August through 1 September 2026. The Amount/Usage CSV and Cost/Billing CSV reconcile to the same total cost.

Here are the results:

  • Total billed tokens: 417,153,568
  • API requests: 962
  • Reconciled API cost: USD 5.014844192
  • Input cache-hit tokens: 413,217,024
  • Input cache-miss tokens: 2,443,289
  • Output tokens: 1,493,255
  • Total input tokens: 415,660,313
  • Input cache-hit rate: 99.4124%

The token total is:

  • 413,217,024 cache-hit input
  • 2,443,289 cache-miss input
  • 1,493,255 output
  • = 417,153,568 billed tokens

A clarification about the headline number: these are billed tokens, not 417 million newly submitted input tokens. The total includes cache-hit input, cache-miss input and generated output.

The dashboard rounds the cost to USD 5.01. The more precise figure, USD 5.014844192, comes from the exported billing data.

Where Did the USD 5.01 Go?

The breakdown is more interesting than the headline number.

  • Billing category Input cache hit: 413,217,024 tokens, USD 3.371224192, 67.22% of total cost
  • Billing category Input cache miss: 2,443,289 tokens, USD 0.566604280, 11.30% of total cost
  • Billing category Output: 1,493,255 tokens, USD 1.077015720, 21.48% of total cost
  • Total: 417,153,568 tokens, USD 5.014844192, 100%

One thing caught my attention: Cache-hit input accounted for 67.22% of the total cost.

At first, a 99.4124% cache-hit rate looks excellent. Most input tokens in this report were billed at the cache-hit rate rather than the cache-miss rate. However, cached tokens are not free. The volume was large enough that cache-hit input still cost USD 3.37.

This led me to an important distinction: Cache optimization is not the same as context optimization.

Cache optimization can lower the unit price of repeated input. Context optimization asks a different question: Did the agent actually need all that context in the first place?

A large context can be stable and cache-friendly while still containing irrelevant or redundant information. A high cache-hit rate does not automatically mean that the agent received the right information.

I want to understand which parts of the context are repeatedly sent, why they are needed, and whether they contribute to completing an accepted engineering task.

Peak and Off-Peak: Another Area Worth Exploring

The historical billing export separates usage into Peak and Off-peak tiers.

  • Off-peak: 348,496,364 tokens, 83.54% token share, USD 3.816337904, 76.10% cost share
  • Peak: 68,657,204 tokens, 16.46% token share, USD 1.198506288, 23.90% cost share
  • Total: 417,153,568 tokens, 100%, USD 5.014844192, 100%

The historical unit prices reflected in my Amount CSV were:

  • Input cache hit: USD 0.007 per million tokens Off-peak, USD 0.014 Peak
  • Input cache miss: USD 0.22 per million tokens Off-peak, USD 0.44 Peak
  • Output: USD 0.66 per million tokens Off-peak, USD 1.32 Peak

In this particular historical dataset, Peak rates were twice the corresponding Off-peak rates.

I also calculated a simple counterfactual:

  • Observed Peak cost: USD 1.198506288
  • Same Peak workload at Off-peak rates: USD 0.599253144
  • Modeled difference: USD 0.599253144

This is a simulation, not an actual saving. It assumes that the same workload could have been moved to an Off-peak window without affecting delivery time or operational outcomes.

For non-urgent work - such as documentation reviews, planned analysis or background test generation - provider-aware scheduling may be worth testing. But production incidents, urgent fixes, security work and deadline-critical tasks should not be delayed just to obtain a lower API rate.

Also, these are historical prices from my billing export. They should not be confused with current DeepSeek pricing. Always check the official DeepSeek pricing page before estimating the cost of a new experiment.

The Input/Output Ratio: A Signal, Not a Score

The aggregate report shows:

  • Input tokens: 415,660,313
  • Output tokens: 1,493,255
  • Input/output ratio: approximately 278.4:1
  • Average across 962 requests: approximately 432,079 input tokens and 1,552 output tokens per request

That ratio is heavily input-weighted. It deserves investigation, but I do not think it is enough to conclude that the agent was inefficient.

A coding agent may send system instructions, tool definitions, previous conversation turns, code excerpts and tool results as input. It may then produce a relatively short tool call while local tools perform file reads, repository searches, edits or terminal commands.

The same aggregate ratio could therefore represent:

  • Necessary instructions and project context
  • Repeated context that could be reduced
  • Large tool outputs sent back to the model
  • Multiple agent iterations or retries
  • Useful local work coordinated through relatively short model responses

The CSV exports do not contain request-level traces, task IDs or tool-call histories. So I cannot determine which explanation applies to my experiment. I would rather acknowledge that limitation than turn an aggregate ratio into an unsupported claim about productivity or wasted tokens.

What I Can Prove - and What I Cannot

I want this case study to be useful to other developers. That means being clear about the difference between evidence and interpretation.

What the billing exports support:

  • 417,153,568 billed tokens
  • 962 API requests
  • USD 5.014844192 in reconciled API cost
  • A large proportion of input cache-hit tokens
  • Both Peak and Off-peak usage during the period
  • Most reported usage attributed to the API key labelled for the Codex configuration

What the billing exports do not establish:

  • That every request originated from the VS Code interface
  • That all 417 million tokens were newly submitted input
  • How many coding tasks or features were completed
  • How many deliverables were accepted
  • Whether the generated code passed all project tests
  • Whether DeepSeek was cheaper than another provider for an equivalent workload
  • Whether prompt optimization caused the observed cache-hit rate

The two screenshots provide visual context for the setup and the usage dashboard. The detailed token and cost calculations come from the exported CSV records. Neither screenshot nor the aggregate billing data can prove task-level engineering acceptance.

That is why I describe USD 5.01 as an observed historical billing result, not proof of productivity or software quality.

What I Want to Improve Next

The most important metric I am missing is not tokens per request. It is the cost of work that the project actually accepts.

My proposed measurement is: Cost per Accepted Task = Attributable API Cost / Number of Accepted Tasks

To calculate this properly, I need to connect API usage to individual engineering tasks and their acceptance evidence. Here are the areas I want to investigate.

Define Task Boundaries Before Asking AI to Code

Each task should have:

  • One clear engineering objective
  • Explicit allowed and forbidden paths
  • Relevant constraints and dependencies
  • Acceptance criteria
  • Required tests and evidence
  • A useful output contract

A bounded task gives the agent a clearer target and makes cost attribution easier.

Select Context Instead of Sending Everything

I want to classify project information into four groups:

  • Mandatory: Always required for the task
  • Conditional: Needed only when the task touches a specific area
  • Excluded: Obsolete, irrelevant or outside the task scope
  • Authoritative: The source that resolves conflicting information

The goal is not to send the smallest possible context. The goal is to provide the minimum sufficient context while preserving requirements, architecture, security and verification.

Keep Reusable Prefixes Stable, but Measure the Result

Where the provider and client support prefix caching, stable instructions and reusable project context may help improve cache reuse. However, a developer-written prompt does not necessarily represent the entire request.

An IDE agent may add system messages, tool definitions, metadata and tool results. I need actual usage telemetry to understand what is being sent and how the provider's cache responds.

DeepSeek explains its caching behavior in the Context Caching documentation.

Reduce Unnecessary Agent Loops and Repeated Tool Output

I want to start measuring:

  • API requests per accepted task
  • Tool calls per accepted task
  • Repeated file reads
  • Repeated or oversized tool output
  • Retry and rework counts
  • Failed and abandoned tasks

Reducing repeated work may help, but fewer calls are not automatically better. The objective is controlled execution, not minimizing every interaction regardless of quality.

Use a Clear Output Contract

For many coding tasks, the final report can focus on:

  • What changed
  • Which files changed
  • Build and test results
  • Known limitations
  • Evidence references
  • Unresolved items

However, architecture, debugging and security tasks may need more detailed explanations. I do not want an arbitrary output limit to remove information needed for engineering review.

The Next Experiment: Measure Accepted Outcomes

I would like to compare four workflow approaches:

  • A - Baseline: Existing workflow with usage and outcome recording
  • B - Prompt Contract: Baseline plus explicit task scope and acceptance criteria
  • C - Context Optimization: B plus a context manifest and targeted retrieval
  • D - Full Optimization: C plus stable-prefix discipline, output contracts and scheduling of deferrable work

For a fair comparison, I need to keep the repository snapshot, task, model, reasoning configuration, tool permissions and acceptance criteria as consistent as possible. I also need to record cache-warm and cache-cold conditions rather than assume they occurred.

The measurements should include:

  • Task ID and repository commit: Connects usage to a unit of work
  • Provider and model ID: Makes the experiment reproducible
  • Request timestamps and pricing tier: Supports correct cost calculation
  • Cache-hit, cache-miss and output tokens: Explains the billing mix
  • Attributable API cost: Measures actual task spend
  • API requests and tool calls: Helps identify agent-loop overhead
  • Retries and rework: Shows repeated effort
  • Changed files: Describes implementation scope
  • Build and test results: Provides technical verification
  • Acceptance status and evidence: Connects cost to an accepted outcome

Only then can I compare cost per accepted task, acceptance rate, rework, test results and time to completion. I do not have those measurements for the historical billing period. That is the next problem I want to solve.

Practical Resources for Developers

I have organized the experiment into a practical lab in my GitHub repository: Beyond Vibe Coding - Optimize AI Coding Costs: DeepSeek + Codex Lab.

You can explore:

  • DeepSeek + Codex integration guide
  • Cache and context optimization guide
  • AI Cost Optimization Standard
  • Task contract template
  • Context manifest template
  • Experiment protocol
  • Evidence register

The AI Cost Optimization Standard is marked Proposed / Experimental. The materials are intended as a starting point for practical learning and further experiments, not as a guarantee of savings.

Why This Is Part of Beyond Vibe Coding

For me, this experiment is part of a continuing journey. Using an AI coding agent is not only about choosing a model or writing a clever prompt. Real software development also needs clear tasks, relevant context, durable project knowledge, engineering authority, continuity and verification.

These are some of the broader ideas I explore in my book: BEYOND VIBE CODING - A Practical Guide to Building Real-World Software with AI by Dong Hong.

The book explores how to move beyond quick AI-generated prototypes toward more disciplined softwar

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.