Mintplex-Labs/anything-llm · error · Error
DeepSeek chat: ${this.model} is not valid for chat completio
Error message
DeepSeek chat: ${this.model} is not valid for chat completion! What it means
Thrown by getChatCompletion when isValidChatCompletionModel returns false. Unlike cache-based providers, DeepSeek's validator calls this.openai.models.list() and checks whether any returned model id matches this.model. If the DeepSeek API is unreachable, returns an empty list (the .catch fallback yields {data:[]}), or the model id is not in the live list, the guard rejects the call.
Source
Thrown at server/utils/AiProviders/deepseek/index.js:99
/**
* Parses and prepends reasoning from the response and returns the full text response.
* @param {Object} response
* @returns {string}
*/
#parseReasoningFromResponse({ message }) {
let textResponse = message?.content;
if (
!!message?.reasoning_content &&
message.reasoning_content.trim().length > 0
)
textResponse = `<think>${message.reasoning_content}</think>${textResponse}`;
return textResponse;
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`DeepSeek chat: ${this.model} is not valid for chat completion!`
);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.chat.completions
.create({
model: this.model,
messages,
temperature,
})
.catch((e) => {
throw new Error(e.message);
})
);
if (
!result?.output?.hasOwnProperty("choices") ||
result?.output?.choices?.length === 0View on GitHub (pinned to 526360e320)
Solutions
- Verify the model id against the live GET https://api.deepseek.com/v1/models response using the same API key.
- Check that DEEPSEEK_API_KEY is valid — if it is expired, models.list() silently returns empty and every model fails.
- Default to 'deepseek-chat' (the constructor fallback) if unsure.
- If the API is temporarily unreachable, retry — the validation is network-dependent and will pass once connectivity is restored.
Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate the model against DeepSeek's live list
const models = await fetch('https://api.deepseek.com/v1/models', {
headers: { Authorization: `Bearer ${process.env.DEEPSEEK_API_KEY}` },
}).then(r => r.json()).catch(() => ({ data: [] }));
const isValid = models.data?.some(m => m.id === modelId);
if (!isValid) throw new Error(`Model ${modelId} not found in DeepSeek /v1/models`); Try / catch
try {
return await deepseek.getChatCompletion(messages, { temperature });
} catch (e) {
if (/is not valid for chat completion/i.test(e.message))
throw new Error(`DeepSeek model "${modelId}" invalid or API unreachable. Check DEEPSEEK_API_KEY and model id.`);
throw e;
} Prevention
- Be aware isValidChatCompletionModel makes a network call — a transient failure or expired key makes every model appear invalid.
- Default to 'deepseek-chat' to minimize invalid-model risk.
- Validate the API key independently before relying on model-list validation.
When it happens
Trigger: DEEPSEEK_MODEL_PREF is set to a model id not returned by GET /v1/models (e.g. a typo or a model DeepSeek retired); the models.list() call fails due to network/auth issues, causing the catch to return an empty data array, which makes every model id fail validation.
Common situations: DeepSeek deprecating 'deepseek-coder' or similar legacy ids; transient network failure to api.deepseek.com during the models.list() call masking a valid model as invalid; an expired API key causing models.list() to 401 and silently return an empty list.
Related errors
- CometAPI chat: ${this.model} is not valid for chat completio
- e.message
- Invalid response body returned from DeepSeek: ${JSON.stringi
- Docker Model Runner chat: ${this.model} is not valid or defi
- FireworksAI chat: ${this.model} is not valid for chat comple
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/cd8ce71f53183558.
Report an issue: GitHub.