Skip to content

Fix DeepSeek chat models failing with unavailable response_format (#1336) - #1337

Open
eldar702 wants to merge 1 commit into
khoj-ai:masterfrom
eldar702:fix/1336-deepseek-response-format
Open

Fix DeepSeek chat models failing with unavailable response_format (#1336)#1337
eldar702 wants to merge 1 commit into
khoj-ai:masterfrom
eldar702:fix/1336-deepseek-response-format

Conversation

@eldar702

@eldar702 eldar702 commented Jun 8, 2026

Copy link
Copy Markdown

Closes #1336.

Problem

Any DeepSeek OpenAI-compatible chat model that is not deepseek-reasoner (e.g. deepseek-chat, the flagship V3) fails every request over the official api.deepseek.com endpoint with HTTP 400 invalid_request_error: This response_format type is unavailable now, so the chat turn is saved with an empty Khoj response.

Fix

get_structured_output_support in src/khoj/processor/conversation/openai/utils.py only special-cased deepseek-reasoner (→ NONE); every other DeepSeek model fell through to StructuredOutputSupport.TOOL. The official DeepSeek API only supports response_format={"type": "json_object"} and rejects tool/json_schema structured output. The fix gates the api.deepseek.com host to StructuredOutputSupport.OBJECT, mirroring the existing api.deepinfra.com / *.ai.azure.com handling in the same function (1 file, 5 LOC, no new deps).

Test

Added tests/test_conversation_utils.py::TestGetStructuredOutputSupport (DB-free, pure-function). test_deepseek_chat_supports_object_output asserts get_structured_output_support("deepseek-chat", "https://api.deepseek.com/v1") == StructuredOutputSupport.OBJECT — it fails before the fix (function returns TOOL) and passes after. Two guard tests keep deepseek-reasoner → NONE and the default OpenAI path gpt-4o → TOOL green.

Verification

  • pytest tests/test_conversation_utils.py -k TestGetStructuredOutputSupport — green (also full file: 14 passed)
  • mypy src/khoj/processor/conversation/openai/utils.py — no new errors introduced (pre-existing baseline unchanged)
  • ruff check / ruff format --check — clean

Note: khoj is AGPL-3.0; this contribution is offered under the same license.

🤖 AI-assistance disclosure: drafted with assistance from Claude (Opus 4.8). All changes reviewed for correctness before submission.

…oj-ai#1336)

get_structured_output_support only special-cased deepseek-reasoner, so
deepseek-chat (and other non-reasoner DeepSeek models served over the
official api.deepseek.com endpoint) fell through to
StructuredOutputSupport.TOOL. The DeepSeek API only supports
response_format={"type": "json_object"} and rejects tool/json_schema
structured output with HTTP 400 "This response_format type is
unavailable now", leaving an empty Khoj response.

Gate the api.deepseek.com host to StructuredOutputSupport.OBJECT,
mirroring the existing deepinfra/azure handling. Add DB-free regression
tests covering deepseek-chat (OBJECT), deepseek-reasoner (NONE) and the
default OpenAI path (TOOL).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@eldar702
eldar702 marked this pull request as ready for review June 10, 2026 06:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeek-compatible OpenAI API fails due to unsupported response_format type

1 participant