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:
| Event | Description |
|---|---|
response.created | The first event; the response has been created with status in_progress |
response.in_progress | The response is being generated |
response.output_item.added / response.output_item.done | An output item (reasoning / message / function_call / custom_tool_call / web_search_call) starts / completes |
response.content_part.added / response.content_part.done | A content part within an output item starts / completes |
response.reasoning_text.delta / response.reasoning_text.done | Incremental chain-of-thought text / the full chain-of-thought text |
response.output_text.delta / response.output_text.done | Incremental output text / the full output text |
response.function_call_arguments.delta / response.function_call_arguments.done | Incremental function call arguments / the full arguments |
response.custom_tool_call_input.delta / response.custom_tool_call_input.done | Incremental custom tool call (apply_patch) input / the full input |
response.web_search_call.in_progress / response.web_search_call.searching / response.web_search_call.completed | Status updates of a server-side web search tool call |
response.completed | The final event when the response completes normally, carrying the full response object including usage |
response.incomplete | The final event when the response is truncated (e.g. reaching max_output_tokens), carrying the full response object |
response.failed | The 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: Anhttp(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 formfile-api-....detail:low/high/original/auto.lowdownsamples the image to 512x512 before inference; the other values keep the original image. Ignored whenfile_idis 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/developermessage items and infunction_call_output/custom_tool_call_outputoutputs. Images insystemorassistantmessages return a400error. - Only vision models (
deepseek-v4-flash-vision-exp) processinput_imageparts; 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_idimage, 64 MiB total withoutfile_idimages 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
| Parameter | Support Status |
|---|---|
model | Supported. deepseek-v4-flash / deepseek-v4-pro / deepseek-v4-flash-vision-exp, see Models & Pricing |
input | Supported. String or input item list; at least one of input and instructions is required |
instructions | Supported. Inserted as the first system message |
stream | Supported |
temperature | Supported (range [0.0, 2.0]; no effect in thinking mode) |
top_p | Supported (no effect in thinking mode) |
max_output_tokens | Supported |
top_logprobs | Supported (range [0, 20]) |
tools | Partially supported. function / web_search supported; other types ignored, see the Tools table below |
tool_choice | Supported. none / auto / required / a specific tool ({"type": "function", "name": ...} or {"type": "web_search"} / {"type": "web_search_2025_08_26"}) |
reasoning | Partially supported. effort supported; summary accepted but no summary is generated |
text | Partially supported. format fully supported; verbosity accepted but has no effect |
user | Supported. See Rate Limit & Isolation |
parallel_tool_calls | Ignored (parallel tool calling is always enabled) |
max_tool_calls | Ignored |
previous_response_id | Not supported (stateless API) |
conversation | Not supported (stateless API) |
store | Not supported. The response always carries store: false |
background | Not supported |
metadata | Not supported |
include | Not supported |
prompt | Not supported |
truncation | Not supported. Requests exceeding the context window return a 400 error |
service_tier | Not supported |
safety_identifier | Not supported |
prompt_cache_key / prompt_cache_retention | Not supported. Context caching is managed automatically, see Context Caching |
context_management | Not supported |
stream_options | Not supported |
Unsupported parameters are silently ignored and do not cause errors, so existing Responses API clients can connect without modification.
Input Items
| Type | Support Status |
|---|---|
message | Supported. 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_call | Supported. Merged into the adjacent assistant message |
function_call_output | Supported. 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 |
reasoning | Supported. Plain-text content is merged into the adjacent assistant message; summary and encrypted_content are not supported |
web_search_call | Supported. Pass back as-is; the server automatically restores the search results |
custom_tool_call / custom_tool_call_output | Supported (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 types | Ignored |
Tools
| Type | Support Status |
|---|---|
function | Supported |
web_search / web_search_2025_08_26 | Supported, executed on the server side. search_context_size and user_location are ignored; server-side auto-continuation is capped at 10 rounds |
custom | Only {"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 tools | Ignored |
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, whereinput_tokens_details.cached_tokensis the number of tokens hitting the context cacheoutput_tokens: number of output tokens, whereoutput_tokens_details.reasoning_tokensis the number of chain-of-thought tokens