Skip to content

pydantic_ai.models.deepseek

Setup

For details on how to set up authentication with these models, see model configuration for DeepSeek.

DeepSeekResponsesModel

Bases: OpenAIResponsesModel

A model that uses DeepSeek’s Responses API.

With a model whose profile sets deepseek_supports_web_tools, as deepseek-flash’s does, WebSearchTool and WebFetchTool run as DeepSeek’s server-side deepseek_web_search and deepseek_read_url tools. Their signed results are kept in the message history and sent back on later requests. With any other model, it behaves like OpenAIResponsesModel.

Apart from __init__, all methods are private or match those of the base class.

Attributes

profile

The model profile.

With deepseek_supports_web_tools, which DeepSeekProvider sets for deepseek-flash, url_citation offsets map to a ContentCitationAnchor. Without it, WebFetchTool leaves the supported native tools, and the model sends and maps what OpenAIResponsesModel does.

Type: DeepSeekModelProfile

Methods

__init__
def __init__(
    model_name: DeepSeekModelName | str,
    *,
    provider: Literal['deepseek'] | Provider[AsyncOpenAI] = 'deepseek',
    profile: ModelProfileSpec | None = None,
    settings: ModelSettings | None = None,
)

Initialize a DeepSeek Responses model.

Parameters

model_name : DeepSeekModelName | str

The name of the DeepSeek model to use.

provider : Literal[‘deepseek’] | Provider[AsyncOpenAI] Default: 'deepseek'

The provider to use. Defaults to 'deepseek'.

profile : ModelProfileSpec | None Default: None

The model profile to use. Defaults to a profile picked by the provider based on the model name.

settings : ModelSettings | None Default: None

Default model settings for this model instance.

supported_native_tools

@classmethod

def supported_native_tools(cls) -> frozenset[type[AbstractNativeTool]]

Return the set of native tool types this model class can handle.

That’s the OpenAIResponsesModel set plus WebFetchTool, for DeepSeek’s URL reading. The profile keeps WebFetchTool only for a model DeepSeek runs its web tools on.

Returns

frozenset[type[AbstractNativeTool]]

unsupported_native_tool_settings
def unsupported_native_tool_settings(native_tool: AbstractNativeTool) -> frozenset[str]

Return native_tool’s restricting settings that the model can’t apply.

DeepSeek’s web tools take none of them. Otherwise, as for OpenAIResponsesModel.

Returns

frozenset[str]

DeepSeekResponsesStreamedResponse

Bases: OpenAIResponsesStreamedResponse

Implementation of StreamedResponse for DeepSeek’s Responses API with its web tools.

DeepSeekChatModel

Bases: OpenAIChatModel

A model that uses DeepSeek’s Chat Completions API.

With a model whose profile sets deepseek_supports_web_tools, as deepseek-flash’s does, WebSearchTool and WebFetchTool run as DeepSeek’s server-side deepseek_web_search and deepseek_read_url tools. Their signed results are kept in the message history and sent back on later requests. With any other model, it behaves like OpenAIChatModel.

Apart from __init__, all methods are private or match those of the base class.

Attributes

profile

The model profile.

With deepseek_supports_web_tools, which DeepSeekProvider sets for deepseek-flash, url_citation offsets map to a ContentCitationAnchor. Without it, WebFetchTool leaves the supported native tools, and the model sends and maps what OpenAIChatModel does.

Type: DeepSeekModelProfile

Methods

__init__
def __init__(
    model_name: DeepSeekModelName | str,
    *,
    provider: Literal['deepseek'] | Provider[AsyncOpenAI] = 'deepseek',
    profile: ModelProfileSpec | None = None,
    settings: ModelSettings | None = None,
)

Initialize a DeepSeek Chat Completions model.

Parameters

model_name : DeepSeekModelName | str

The name of the DeepSeek model to use.

provider : Literal[‘deepseek’] | Provider[AsyncOpenAI] Default: 'deepseek'

The provider to use. Defaults to 'deepseek'.

profile : ModelProfileSpec | None Default: None

The model profile to use. Defaults to a profile picked by the provider based on the model name.

settings : ModelSettings | None Default: None

Default model settings for this model instance.

supported_native_tools

@classmethod

def supported_native_tools(cls) -> frozenset[type[AbstractNativeTool]]

Return the set of native tool types this model class can handle.

That’s the OpenAIChatModel set plus WebFetchTool, for DeepSeek’s URL reading. The profile keeps WebFetchTool only for a model DeepSeek runs its web tools on.

Returns

frozenset[type[AbstractNativeTool]]

DeepSeekChatStreamedResponse

Bases: OpenAIStreamedResponse

Implementation of StreamedResponse for DeepSeek’s Chat Completions API with its web tools.