Mintplex-Labs/anything-llm · error · Error
CometAPI chat: ${this.model} is not valid for chat completio
Error message
CometAPI chat: ${this.model} is not valid for chat completion! What it means
Thrown by getChatCompletion when isValidChatCompletionModel returns false. That method syncs the local model cache (storage/models/cometapi/models.json) from the CometAPI /models endpoint, then checks whether this.model is a key in that cached object. If the model id is absent — stale cache, never-synced cache, or an invalid/deprecated model — the chat call is blocked before any API request is made.
Source
Thrown at server/utils/AiProviders/cometapi/index.js:198
attachments = [],
}) {
const prompt = {
role: "system",
content: `${systemPrompt}${this.#appendContext(contextTexts)}`,
};
return [
prompt,
...formatChatHistory(chatHistory, this.#generateContent),
{
role: "user",
content: this.#generateContent({ userPrompt, attachments }),
},
];
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`CometAPI 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
- Call the CometAPI /v1/models endpoint with the API key to confirm the model id is currently listed and matches exactly (including casing).
- Delete storage/models/cometapi/models.json and the .cached_at file to force a fresh sync, then retry.
- Update COMETAPI_LLM_MODEL_PREF (or the workspace model selection) to a currently valid CometAPI model id.
- Verify the storage directory is writable so the model cache can be persisted after sync.
Defensive patterns
Strategy: validation
Validate before calling
const llm = new CometApiLLM(embedder, modelPref);
const isValid = await llm.isValidChatCompletionModel(llm.model);
if (!isValid)
throw new Error(`Model "${llm.model}" is not in the CometAPI catalog. Sync the cache or pick a valid id.`); Try / catch
try {
return await llm.getChatCompletion(messages, { temperature });
} catch (e) {
if (/is not valid for chat completion/i.test(e.message)) {
// force cache refresh and retry once
fs.unlinkSync(llm.cacheModelPath);
await llm.isValidChatCompletionModel(llm.model); // triggers resync
return await llm.getChatCompletion(messages, { temperature });
}
throw e;
} Prevention
- After selecting a CometAPI model, trigger a model cache sync before the first chat request.
- Ensure the storage/models/cometapi directory is writable so the cache persists.
- Validate the model id against the CometAPI /v1/models endpoint when saving provider settings.
When it happens
Trigger: COMETAPI_LLM_MODEL_PREF is set to a model id that CometAPI no longer lists; the models.json cache file does not exist (first run before sync) or is corrupt; the sync fetch failed silently leaving an empty cache; the model id has trailing whitespace or different casing than the catalog.
Common situations: First-ever CometAPI request on a fresh install where the model cache has not been populated; CometAPI retiring a model and the saved preference still points to it; a typo in the model preference env var; the storage directory is read-only so the cache write fails.
Related errors
- FireworksAI chat: ${this.model} is not valid for chat comple
- ${e.message}
- DeepSeek chat: ${this.model} is not valid for chat completio
- Docker Model Runner chat: ${this.model} is not valid or defi
- Perplexity chat: ${this.model} is not valid for chat complet
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/f234e32b7a5b429f.
Report an issue: GitHub.