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="", 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 responseobject includingusage |
| response.incomplete | The final event when the response is truncated (e.g. reaching max_output_tokens), carrying the fullresponseobject |
| response.failed | The final event when the response fails, carrying the full responseobject witherrordetails |

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, see Models & Pricing |
| input | Supported. String or input item list; at least one of inputandinstructionsis 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_searchsupported; 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. effortsupported;summaryaccepted but no summary is generated |
| text | Partially supported. formatfully supported;verbosityaccepted 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 400error |
| 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(developeris treated assystem); content supports strings andinput_text/output_textcontent parts. Image and file inputs are not supported (input_imageparts do not cause an error, but are replaced with a placeholder text) |
| function_call | Supported. Merged into the adjacent assistant message |
| function_call_output | Supported |
| reasoning | Supported. Plain-text contentis merged into the adjacent assistant message;summaryandencrypted_contentare not supported |
| web_search_call | Supported. Pass back as-is; the server automatically restores the search results |
| Other types | Ignored |

Toolsâ

| Type | Support Status |
|---|---|
| function | Supported |
| web_search/web_search_2025_08_26 | Supported, executed on the server side. search_context_sizeanduser_locationare ignored |
| custom | Only {"type": "custom", "name": "apply_patch"}is supported (for Codex compatibility); other names return a400error |
| 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, where- input_tokens_details.cached_tokensis the number of tokens hitting the context cache
  • output_tokens: number of output tokens, where- output_tokens_details.reasoning_tokensis the number of chain-of-thought tokens