# DeepSeek API Quirks

Provider-specific behaviors that differ from OpenAI's implementation.

## `response_format: json_object` Requires "json" in Prompt

**Error:** `400 - Prompt must contain the word 'json' in some form to use 'response_format' of type 'json_object'.`

**Fix:** Add the word `json` or `JSON` anywhere in the system prompt. Examples:

```
你必须以 JSON 格式输出回复，不要输出任何其他内容。
```

or

```
Output your response in JSON format.
```

Even a simple mention like `"json"` in a comment somewhere in the prompt suffices. Without this, the API rejects structured output mode entirely.

## `reasoning_content` with `finish_reason: "length"`

When `max_tokens` is too low, DeepSeek v4 models may use all tokens on internal reasoning (`reasoning_content`) before generating the actual response. The `content` field will be empty while `reasoning_content` is populated. Always ensure `max_tokens` is large enough (at least 200-300) when using pro models with structured output.

## JSON Output Stability

DeepSeek v4 models sometimes wrap JSON responses in markdown code blocks (` ```json ... ``` `) even when `response_format: { type: 'json_object' }` is set. Always strip markdown wrappers before parsing:

```js
const cleanRaw = raw.replace(/^```(?:json)?\s*/i, '').replace(/\s*```$/i, '');
```

## API Key Format

DeepSeek API keys are 35 characters, start with `sk-`. Compatible with the OpenAI SDK — no special configuration needed beyond setting `baseURL: 'https://api.deepseek.com'`.
