Module 3 of 3 · 45 min
DeepSeek API Workflows, Tool Calling & Cost Optimization
Build high-throughput, low-cost applications using the DeepSeek API, prompt caching, and function calling contracts.
Core concept
By the end
You will be able to
- Integrate DeepSeek OpenAI-compatible API endpoints in TypeScript and Python.
- Leverage automatic context caching for up to 90% input token cost reduction.
- Build resilient tool-calling workflows with schema validation and retry policies.
01
OpenAI-Compatible API with Context Caching
DeepSeek exposes an OpenAI-compatible API, allowing direct reuse of standard SDKs by changing `base_url`. Context caching automatically identifies prefix matches across requests, reducing input token pricing significantly.
DeepSeek Client with Tool Calling
python
from openai import OpenAI
client = OpenAI(
api_key="your-deepseek-api-key",
base_url="https://api.deepseek.com"
)
response = client.chat.completions.create(
model="deepseek-chat",
messages=[{"role": "user", "content": "What is 2+2?"}],
stream=False
)
print(response.choices[0].message.content)Practice activity
Implement DeepSeek Tool-Calling Agent with Context Caching
- Create an OpenAI-compatible client targeting `https://api.deepseek.com`.
- Define a typed weather tool and execute function calling loop.
- Verify cached token hit rate across 5 sequential requests.
What to produce
- API execution receipt showing cached token discounts and tool execution outputs.
Reflect before continuing
How does prompt structure and prefix stability affect context cache hit rates?
Evidence
Sources and verification
- DeepSeek API Documentation & Context Caching PricingDeepSeek · verified 2026-08-22
Knowledge check
Make it stick.
Choose the strongest answer for each question. Your attempts become part of your account transcript.