DeepSeekAnthropicProvider#
Connect a provider and configure retries, credentials, and transport. See the guide.
- class zett_agent.providers.deepseek.DeepSeekAnthropicProvider(model, api_key, transport=None, *, base_url=None, retry=RetryOptions(base_delay=0.25, max_delay=8.0, max_retries=3), timeout=TimeoutOptions(connect=5.0, first_byte=60.0, idle=600.0), max_tokens=16384, extra_headers=None, extra_query=None, extra_body=None)[source]#
Stream DeepSeek through its Anthropic Messages protocol.
Use it for a tool that speaks Messages, or to keep a conversation on the protocol the rest of the application uses.
DeepSeekProvideris the same service over Chat Completions.- Parameters:
model (str) – DeepSeek model identifier, such as
deepseek-v4-pro. A name that starts withclaudeis accepted by the service and mapped to a DeepSeek model; any other name that is not DeepSeek’s is a 400.api_key (str) – API credential supplied by the application.
transport (httpx.AsyncBaseTransport | None) – Optional HTTPX transport for custom routing or tests.
base_url (str | None) – API root; None uses
https://api.deepseek.com/anthropic.retry (RetryOptions) – Model-owned retry/backoff policy; never restarts an emitted stream.
timeout (TimeoutOptions) – How long the provider may stay silent before the request is given up on. See
TimeoutOptions.max_tokens (int) – Output budget for one response.
extra_headers (Mapping[str, str] | None) – HTTP headers sent on every request after the adapter’s own.
extra_query (Mapping[str, str] | None) – URL query parameters sent on every request.
extra_body (dict[str, JsonValue]) – JSON fields merged into every request body last.
Note
DeepSeek ignores
budget_tokensandcache_control, so neither is sent. Thinking is switched on or off withthinking, and the level goes inoutput_config.effortfor the V4 models. Thinking blocks are sent back unchanged. Redacted thinking, documents and search results are not supported by the service.Examples
Stream a DeepSeek model over Messages:
model = DeepSeekAnthropicProvider( model="deepseek-v4-pro", api_key=os.environ["DEEPSEEK_API_KEY"], ) try: client = await create_agent(model) print((await client.run("Explain this function")).content) finally: await model.aclose()
- provider_name: str = 'deepseek-anthropic'#
Name stored on messages this provider produced. Signed blocks are sent back only to the same name and model.
- request_fields(request)[source]#
Switch thinking on or off, without a token budget, and give the V4 models their level.
- Parameters:
request (ModelRequest)
- Return type:
dict[str, JsonValue]
- async aclose()#
Close the owned SDK connection pool.
- Return type:
None
- bearer_auth: ClassVar[bool] = False#
Authenticate with
Authorization: Beareras well asx-api-key. The services that take only the bearer token ignore the other header.
- finish_usage(usage, update)#
Fold the
usageobject of themessage_deltaevent intousage.The default takes the final
output_tokens, which is the only count Anthropic updates.- Parameters:
usage (ModelUsage)
update (Mapping[str, JsonValue])
- Return type:
- mark_cache(body, client_tools)#
Put cache markers into
body(and the tool definitions inclient_tools).The default marks Anthropic’s breakpoints on the largest stable request prefixes: the tool definitions, the whole system prompt, and the conversation so far. Anthropic caches only what a
cache_controlmarker asks for, then reads each cached prefix at a fraction of the input price. A prefix shorter than the model’s minimum cacheable length is ignored silently. Nothing is marked unlessprompt_cacheis on.
- message_stop(finish_reason, details, *, has_tool_calls)#
Say why the response ended, from
stop_reasonandstop_details.
- native_deferred_tools: bool = False#
See
zett_agent.model.NativeDeferredToolsModel.native_deferred_tools. Only Anthropic itself loads adefer_loadingtool when atool_referencenames it.
- response: bool = False#
Whether this adapter uses a Responses-style endpoint instead of its provider’s traditional message or chat-completions endpoint. Only the providers read it; the runtime does not.
- start_usage(usage)#
Read the
usageobject of themessage_startevent.Cache reads and writes are reported next to
input_tokens, not inside it, so the total input is their sum.- Parameters:
usage (Mapping[str, JsonValue])
- Return type:
- status_error(error)#
Turn an SDK failure from opening the request into the typed error the runtime reports.
- Parameters:
error (AnthropicError)
- Return type:
- sync(*, runtime=None)#
Return a context-managed synchronous view; optionally share a runtime.
Omitting runtime creates a new background thread for this view. Passing an existing runtime reuses its loop and leaves its shutdown to the caller. This API is for service entry points, not Extension lifecycle hooks.
Examples
Use a model or tool from a plain function:
with read_file.sync() as read: result = read({"path": "README.md"})
- Parameters:
runtime (SyncRuntime | None)
- Return type:
SyncObject[Self]
- vendor_headers()#
Return the headers this service wants on every request.
They are sent before
extra_headers, so the application can still replace one.- Return type:
dict[str, str]