DeepSeek¶
An OpenAI-compatible dialect with three deltas that would otherwise cost a developer silently: reasoning arrives on its own channel, thinking is on by default, and cache accounting is automatic and split.
Setup¶
import anyinfer as ai
client = ai.Client(
[
ai.ProviderSettings.of("deepseek", api_key="env://DEEPSEEK_API_KEY"),
]
)
result = client.generate(prompt, target="deepseek:deepseek-v4-pro")
Two models are served: deepseek-v4-flash and deepseek-v4-pro. The old
deepseek-chat / deepseek-reasoner aliases were discontinued in July 2026.
Reasoning¶
Thinking is on by default. Chain-of-thought streams as ReasoningDelta events,
separate from the answer:
with client.stream(prompt, target="deepseek:deepseek-v4-pro") as stream:
for event in stream:
if isinstance(event, ai.ReasoningDelta):
print("[thinking]", event.text, end="")
elif isinstance(event, ai.TextDelta):
print(event.text, end="")
Requesting an effort level enables thinking explicitly and sets the level. Because
DeepSeek accepts low/high/max, AnyInfer maps minimal and low to low, and
medium and high to high, rather than sending a value the API would rewrite:
result = client.generate(prompt, target="deepseek:deepseek-v4-pro", reasoning="low")
To turn thinking off (a behavior change, not an effort setting):
client.generate(
prompt,
target="deepseek:deepseek-v4-pro",
provider_options={"deepseek": {"thinking": {"type": "disabled"}}},
)
Sampling is ignored while thinking
DeepSeek silently discards temperature and top_p in thinking mode, which is the
default. AnyInfer declares both as ignored, so setting one raises a
ParameterDropped telemetry event instead of silently
doing nothing.
Cache Accounting¶
Context caching is automatic: no opt-in, no cache-control parameters. DeepSeek reports the split, and cache hits bill at a much lower rate:
result = client.generate(long_prompt, target="deepseek:deepseek-v4-flash")
print(result.usage.input_tokens) # hits + misses
print(result.usage.cache_read_tokens) # the part that was cheap
Cost is a ceiling here
The bundled pricing table records the standard (cache-miss) rate, so usage.cost_usd
overstates spend on cache-heavy workloads; supply
capability_overrides for the
blended rate.
The Anthropic-Compatible Endpoint¶
DeepSeek also exposes a Messages endpoint at https://api.deepseek.com/anthropic, which
the Anthropic adapter serves through a base-URL override; see
pointing that adapter elsewhere. Use the
native deepseek: provider unless Messages-dialect behavior is specifically needed; the
reasoning channel and cache accounting above are only wired there.
Wire Contract¶
For the exact request/response fields this adapter depends on, see contracts/deepseek.md.