Skip to main content

Build a Chatbot

The DeepSeek API offers the same conversation features as DeepSeek Chat on the web and in the app: web search, deep thinking search, file input and URL reading, plus basic risk control for model content safety. You can use them to build your own chatbot.

The service runs the searches and URL reading. Your client only shows the returned blocks and passes them back unchanged in the next round.


Feature Map​

Chatbot featureDescriptionGuide
Web searchWith thinking disabled and the deepseek_web_search tool enabled, the model runs web or image searches as the question requires and answers with citationsWeb Search
Deep thinking searchWith thinking enabled and the deepseek_web_search tool enabled, the model searches the web and reads links on its own over multiple reasoning stepsDeep Thinking Search
File inputUpload files such as PDF, Word, PowerPoint and image files; after plain-text extraction or rich-layout parsing, they are added to the conversation context for the model to answer fromFile Parsing
URL readingWith the deepseek_read_url tool enabled, the model detects links in the user message, fetches the pages and answers with them in contextURL Reading
Model content safetyWith the safety check parameter enabled, we provide basic risk control: the model input and output are reviewed, and a refusal marker is returned when a risk is found. If you provide a service to the public, enable this parameter and fulfill obligations such as content safety review, large model registration and AI labelingModel Content Safety
User metadata markerTell the model the current date and the user's location and language, so that answers fit the user's situationUser Metadata Marker
Conversation titleGenerates a short title from the conversation when the answer endsConversation Title
Read aloudTurns the model's answer into speechText to Speech
Voice inputTranscribes the user's speech into text to send as a messageSpeech to Text

Demo​

DeepSeek provides an open-source demo chat client that shows how to build a chatbot with these APIs. Enter your API key to start. You can also import the chat history you exported from DeepSeek Chat and continue your conversations.

Your API key, conversations and uploaded images are stored only in your browser. The demo is for demonstration only.

The demo shows:

  • Web search, deep thinking search and URL reading
  • Uploading images and documents
  • Model content safety, including image review
  • Conversation titles, and renaming and deleting conversations
  • Editing a message, regenerating, and continuing a reply
  • Reading answers aloud, and voice input
  • Choosing a language and location in the settings, which are passed to the model as the user metadata marker
  • Importing and exporting chat history (an import replaces the existing history)
  • Markdown rendering, including Mermaid diagrams
  • A Chinese and English interface, with light and dark themes

Choose a Protocol​

The chat features are available in the Messages API, the Responses API and the Chat Completions API.

ProtocolEndpoint
MessagesPOST https://api.deepseek.com/anthropic/v1/messages
ResponsesPOST https://api.deepseek.com/responses
Chat CompletionsPOST https://api.deepseek.com/chat/completions

Use the deepseek-flash model.


Quick Example​

A streaming request with the web tools, safety review and the conversation title enabled:

curl https://api.deepseek.com/anthropic/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: ${DEEPSEEK_API_KEY}" \
-d '{
"model": "deepseek-flash",
"thinking": {"type": "enabled"},
"tools": [
{"type": "deepseek_web_search", "name": "deepseek_web_search"},
{"type": "deepseek_read_url", "name": "deepseek_read_url"}
],
"safety_check": {"level": "high"},
"title": {"enabled": true},
"messages": [{"role": "user", "content": "What is new in DeepSeek V4.1?"}],
"stream": true
}'

The stream of this request, shortened:

event: message_start
data: {"type":"message_start","message":{"id":"b161a9be-...","type":"message","role":"assistant","model":"deepseek-flash","content":[],"stop_reason":null,"stop_sequence":null,"usage":{"input_tokens":40,"cache_creation_input_tokens":0,"cache_read_input_tokens":0,"output_tokens":0,"service_tier":"standard"}}}

event: content_block_start
data: {"type":"content_block_start","index":0,"content_block":{"type":"thinking","thinking":"","signature":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"thinking_delta","thinking":"..."}}

event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"signature_delta","signature":"b161a9be-..."}}

event: content_block_stop
data: {"type":"content_block_stop","index":0}

event: content_block_start
data: {"type":"content_block_start","index":1,"content_block":{"type":"server_tool_use","id":"srvtoolu_ds_00_b2baebaf...","name":"deepseek_web_search","input":{"action":"search","queries":["DeepSeek V4.1 new features","DeepSeek V4.1 release notes"]},"caller":{"type":"direct"},"kind":"deep_search"}}

event: content_block_stop
data: {"type":"content_block_stop","index":1}

event: content_block_start
data: {"type":"content_block_start","index":2,"content_block":{"type":"web_search_tool_result","tool_use_id":"srvtoolu_ds_00_b2baebaf...","content":[{"type":"web_search_result","title":"...","url":"https://api-docs.deepseek.com/news/news261017/","encrypted_content":"...","page_age":"2026-10-16T16:00:00+00:00","snippet":"...","site_name":"DeepSeek","site_icon":"https://cdn.deepseek.com/site-icons/deepseek.com"}],"kind":"deep_search"}}

...

event: content_block_start
data: {"type":"content_block_start","index":15,"content_block":{"type":"text","text":""}}

event: content_block_delta
data: {"type":"content_block_delta","index":15,"delta":{"type":"text_delta","text":"Deep"}}

event: content_block_delta
data: {"type":"content_block_delta","index":15,"delta":{"type":"citations_delta","citation":{"type":"web_search_result_location","url":"https://api-docs.deepseek.com/news/news261017/","title":"...","encrypted_index":"","cited_text":"..."}}}

...

event: message_delta
data: {"type":"message_delta","delta":{"stop_reason":"end_turn","stop_sequence":null,"title":"..."},"usage":{"input_tokens":9078,"cache_creation_input_tokens":0,"cache_read_input_tokens":4096,"output_tokens":1686,"service_tier":"standard","server_tool_use":{"web_search_requests":1,"web_fetch_requests":0,"tool_search":2,"tool_fetch":0,"tool_image_search":0}}}

event: message_stop
data: {"type":"message_stop"}

Render a Response​

A chatbot response contains several kinds of content blocks. The screenshot below marks where each block appears in DeepSeek Chat.

A DeepSeek Chat conversation with the thinking, search, page reading and answer blocks marked
BlockWhat to show
thinkingThe collapsible thinking panel
server_tool_use + web_search_tool_resultA search step with result cards (title, site name, icon)
server_tool_use + web_fetch_tool_resultA page that was opened or a link that was read
text with citationsThe answer, with citation markers that link to the sources
stop_reason: "refusal"Replace the answer with your refusal message

See Web Tools and Model Content Safety for the block formats.


Ignored Parameters​

When a request declares deepseek_web_search or deepseek_read_url, sets safety_check to high, or enables title, the service decides the following parameters, and the values in the request are ignored:

ProtocolIgnored parameters
Messagestemperature, top_p, top_k, stop_sequences, thinking.budget_tokens, preserve_thinking, tool_choice.disable_parallel_tool_use, metadata (except user_id)
Responsestemperature, top_p, reasoning.summary, text.verbosity, include, max_tool_calls, truncation, metadata, parallel_tool_calls, store
Chat Completionstemperature, top_p, frequency_penalty, presence_penalty, stop, seed, n, preserve_thinking, parallel_tool_calls

max_tokens (max_output_tokens in the Responses API) works as usual. It limits the output of each inference step in a round, not the total output of the round.


Compliance Requirements​

  • With the safety check parameter enabled, we provide basic risk control: the model input and output are reviewed, and a refusal is returned when a risk is detected. If you provide a service to the public, enable this parameter, and fulfill on your own the obligations of a service provider, such as content safety review, large model registration and AI labeling.
  • Please comply with our Open Platform Terms of Service: DeepSeek Open Platform Terms of Service.