Mintplex-Labs/anything-llm · error · Error
OpenAI chat: ${this.model} is not valid for chat completion!
Error message
OpenAI chat: ${this.model} is not valid for chat completion! What it means
Pre-flight model validation in getChatCompletion. isValidChatCompletionModel short-circuits to true for ids containing 'gpt' or starting with 'o'; for any other id it calls openai.models.retrieve(modelName) and returns false if that 404s or errors. This throw fires only for non-gpt/non-o ids that the OpenAI account cannot retrieve.
Source
Thrown at server/utils/AiProviders/openAi/index.js:150
* @param {string} modelName
* @param {number} temperature
* @returns {number}
*/
#temperature(modelName, temperature) {
// For models that don't support temperature
// OpenAI accepts temperature 1
const NO_TEMP_MODELS = ["o", "gpt-5"];
if (NO_TEMP_MODELS.some((prefix) => modelName.startsWith(prefix))) {
return 1;
}
return temperature;
}
async getChatCompletion(messages = null, { temperature = 0.7 }) {
if (!(await this.isValidChatCompletionModel(this.model)))
throw new Error(
`OpenAI chat: ${this.model} is not valid for chat completion!`
);
const result = await LLMPerformanceMonitor.measureAsyncFunction(
this.openai.responses
.create({
model: this.model,
input: messages,
store: false,
temperature: this.#temperature(this.model, temperature),
})
.catch((e) => {
throw new Error(e.message);
})
);
if (!result.output.hasOwnProperty("output_text")) return null;
View on GitHub (pinned to 526360e320)
Solutions
- List accessible models with the same key: 'openai models list' / GET /v1/models and confirm the id appears.
- Switch to a gpt- or o- prefixed model, or correct the typo in OPEN_MODEL_PREF.
- For fine-tunes, ensure the key belongs to the org/project that owns the model.
- If the model was deprecated, choose the recommended successor.
Example fix
// before - non-gpt id that 404s on models.retrieve OPEN_MODEL_PREF=my-custom-ft-model // after - use an accessible id or a gpt- prefix short-circuit OPEN_MODEL_PREF=gpt-4.1-mini
Defensive patterns
Strategy: validation
Validate before calling
const isAccessibleOpenAiModel = async (openai, model) => {
if (model.toLowerCase().includes('gpt') || model.toLowerCase().startsWith('o')) return true;
try { await openai.models.retrieve(model); return true; } catch { return false; }
};
if (!(await isAccessibleOpenAiModel(openai, modelId)))
throw new Error(`OpenAI model '${modelId}' is not accessible with this key.`); Type guard
const isPresetOpenAiModel = (m) =>
typeof m === 'string' && (m.toLowerCase().includes('gpt') || m.toLowerCase().startsWith('o')); Prevention
- Use gpt- or o- prefixed ids where possible (they short-circuit validation without an API call).
- For fine-tunes, use a key from the owning org/project.
- List accessible models with the active key before configuring OPEN_MODEL_PREF.
When it happens
Trigger: this.model is a non-gpt/non-o id that does not exist, is deprecated, is a fine-tune from another org/project, or the API key lacks access; openai.models.retrieve rejects.
Common situations: Fine-tuned model id scoped to a different organization/project; deprecated model id still saved as OPEN_MODEL_PREF; typo in the model id; new model name not yet retrievable; key without project access.
Related errors
- No base URL was set.
- No token context limit was set.
- No NVIDIA NIM token context limit was set.
- OMLX must have a valid model set.
- No OpenAI API key was set.
AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13).
Data as JSON: /api/errors/28909f92f1139535.
Report an issue: GitHub.