close
Skip to main content

Using the Responses API

To meet the demand for Codex, our API now supports the Responses API format, with the base_url being https://api.deepseek.com.

With a simple configuration, you can use DeepSeek models in Codex.

Integrating DeepSeek Models into Codex

Please refer to Integrate with Codex.

Calling DeepSeek Models via the Responses API

# Please install OpenAI SDK first: `pip3 install openai`
from openai import OpenAI

client = OpenAI(api_key="<your DeepSeek API Key>", base_url="https://api.deepseek.com")

response = client.responses.create(
model="deepseek-v4-flash",
instructions="You are a helpful assistant.",
input="Hi, how are you?",
)

print(response.output_text)

Streaming

Set stream: true to receive the response as a sequence of semantic server-sent events (SSE). Each event carries an event field indicating the event type, and a monotonically increasing sequence_number. The stream ends with a response.completed / response.incomplete / response.failed event — there is no data: [DONE] message.

stream = client.responses.create(
model="deepseek-v4-flash",
instructions="You are a helpful assistant.",
input="Hi, how are you?",
stream=True,
)

for event in stream:
if event.type == "response.output_text.delta":
print(event.delta, end="")

The full list of events:

EventDescription
response.createdThe first event; the response has been created with status in_progress
response.in_progressThe response is being generated
response.output_item.added / response.output_item.doneAn output item (reasoning / message / function_call / custom_tool_call / web_search_call) starts / completes
response.content_part.added / response.content_part.doneA content part within an output item starts / completes
response.reasoning_text.delta / response.reasoning_text.doneIncremental chain-of-thought text / the full chain-of-thought text
response.output_text.delta / response.output_text.doneIncremental output text / the full output text
response.function_call_arguments.delta / response.function_call_arguments.doneIncremental function call arguments / the full arguments
response.custom_tool_call_input.delta / response.custom_tool_call_input.doneIncremental custom tool call (apply_patch) input / the full input
response.web_search_call.in_progress / response.web_search_call.searching / response.web_search_call.completedStatus updates of a server-side web search tool call
response.completedThe final event when the response completes normally, carrying the full response object including usage
response.incompleteThe final event when the response is truncated (e.g. reaching max_output_tokens), carrying the full response object
response.failedThe final event when the response fails, carrying the full response object with error details

Image Input

The Responses API accepts images with the deepseek-v4-flash-vision-exp model. The same image limits and supported formats as Chat Completions apply.

Images are provided via an input_image content part in a message item, with either image_url (an http(s) URL or a base64 data URL) or file_id (an image uploaded via the Files API):

response = client.responses.create(
model="deepseek-v4-flash-vision-exp",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "What is in this image?"},
{"type": "input_image", "image_url": "https://example.com/image.jpg", "detail": "low"},
],
}
],
)
print(response.output_text)

input_image parts may also appear in the output of function_call_output / custom_tool_call_output items, so the model can receive images produced by your tools:

input=[
{"role": "user", "content": "Read the screenshot the tool returned."},
{"type": "function_call", "call_id": "fc1", "name": "take_screenshot", "arguments": "{}"},
{"type": "function_call_output", "call_id": "fc1",
"output": [{"type": "input_image", "image_url": "data:image/png;base64,<BASE64_DATA>"}]},
]

input_image Fields

  • image_url: An http(s) URL (at most 8192 characters) or a base64-encoded data URL (data:image/jpeg;base64,...). Supported formats: JPEG, PNG, GIF, WebP.
  • file_id: The ID of an image uploaded via the Files API, of the form file-api-....
  • detail: low / high / original / auto. low downsamples the image to 512x512 before inference; the other values keep the original image. Ignored when file_id is set.

image_url and file_id are mutually exclusive: passing neither returns a 400 error ("input_image must have image_url or file_id"), and passing both returns a 400 error ("input_image cannot have both image_url and file_id").

Restrictions

  • Images are allowed only in user / developer message items and in function_call_output / custom_tool_call_output outputs. Images in system or assistant messages return a 400 error.
  • Only vision models (deepseek-v4-flash-vision-exp) process input_image parts; with other models they are replaced with a placeholder text.
  • The same shared image limits as Chat Completions apply (32 MiB per inline image, 64 MiB per file_id image, 64 MiB total without file_id images or up to 200 MiB with them, 600 images per request, etc.) — see Vision: Limits.

Compatibility Details

This section lists the compatibility details of the DeepSeek API with the Responses API. For the full Responses API format definition, please refer to the official OpenAI API reference.

Top-level Request Parameters

ParameterSupport Status
modelSupported. deepseek-v4-flash / deepseek-v4-pro / deepseek-v4-flash-vision-exp, see Models & Pricing
inputSupported. String or input item list; at least one of input and instructions is required
instructionsSupported. Inserted as the first system message
streamSupported
temperatureSupported (range [0.0, 2.0]; no effect in thinking mode)
top_pSupported (no effect in thinking mode)
max_output_tokensSupported
top_logprobsSupported (range [0, 20])
toolsPartially supported. function / web_search supported; other types ignored, see the Tools table below
tool_choiceSupported. none / auto / required / a specific tool ({"type": "function", "name": ...} or {"type": "web_search"} / {"type": "web_search_2025_08_26"})
reasoningPartially supported. effort supported; summary accepted but no summary is generated
textPartially supported. format fully supported; verbosity accepted but has no effect
userSupported. See Rate Limit & Isolation
parallel_tool_callsIgnored (parallel tool calling is always enabled)
max_tool_callsIgnored
previous_response_idNot supported (stateless API)
conversationNot supported (stateless API)
storeNot supported. The response always carries store: false
backgroundNot supported
metadataNot supported
includeNot supported
promptNot supported
truncationNot supported. Requests exceeding the context window return a 400 error
service_tierNot supported
safety_identifierNot supported
prompt_cache_key / prompt_cache_retentionNot supported. Context caching is managed automatically, see Context Caching
context_managementNot supported
stream_optionsNot supported

Unsupported parameters are silently ignored and do not cause errors, so existing Responses API clients can connect without modification.

Input Items

TypeSupport Status
messageSupported. Roles user / assistant / system / developer (developer is treated as user); content supports strings and input_text / output_text / input_image content parts. With the deepseek-v4-flash-vision-exp model, input_image parts are processed as real images (allowed in user / developer messages only; images in system / assistant messages return a 400 error); with other models they are replaced with a placeholder text. File inputs are not supported
function_callSupported. Merged into the adjacent assistant message
function_call_outputSupported. The output may be a string or a list of content parts; with the deepseek-v4-flash-vision-exp model, input_image parts in the output are processed as real images
reasoningSupported. Plain-text content is merged into the adjacent assistant message; summary and encrypted_content are not supported
web_search_callSupported. Pass back as-is; the server automatically restores the search results
custom_tool_call / custom_tool_call_outputSupported (for the apply_patch custom tool, with call_id pairing validation). With the deepseek-v4-flash-vision-exp model, input_image parts in the output are processed as real images
Other typesIgnored

Tools

TypeSupport Status
functionSupported
web_search / web_search_2025_08_26Supported, executed on the server side. search_context_size and user_location are ignored; server-side auto-continuation is capped at 10 rounds
customOnly {"type": "custom", "name": "apply_patch"} is supported (for Codex compatibility); other names return a 400 error
file_search / code_interpreter / computer_use / mcp / other built-in toolsIgnored

Response Fields

The response object is compatible with the OpenAI Responses API response structure. Fields that depend on unsupported capabilities always take fixed values (e.g. store: false, previous_response_id: null, parallel_tool_calls: true).

Token usage is returned in usage:

  • input_tokens: number of input tokens, where input_tokens_details.cached_tokens is the number of tokens hitting the context cache
  • output_tokens: number of output tokens, where output_tokens_details.reasoning_tokens is the number of chain-of-thought tokens