{"record":{"id":"28909f92f1139535","repo":"Mintplex-Labs/anything-llm","slug":"openai-chat-this-model-is-not-valid-for-chat-c","errorCode":null,"errorMessage":"OpenAI chat: ${this.model} is not valid for chat completion!","messagePattern":"OpenAI chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/openAi/index.js","lineNumber":150,"sourceCode":"   * @param {string} modelName\n   * @param {number} temperature\n   * @returns {number}\n   */\n  #temperature(modelName, temperature) {\n    // For models that don't support temperature\n    // OpenAI accepts temperature 1\n    const NO_TEMP_MODELS = [\"o\", \"gpt-5\"];\n\n    if (NO_TEMP_MODELS.some((prefix) => modelName.startsWith(prefix))) {\n      return 1;\n    }\n\n    return temperature;\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `OpenAI chat: ${this.model} is not valid for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.responses\n        .create({\n          model: this.model,\n          input: messages,\n          store: false,\n          temperature: this.#temperature(this.model, temperature),\n        })\n        .catch((e) => {\n          throw new Error(e.message);\n        })\n    );\n\n    if (!result.output.hasOwnProperty(\"output_text\")) return null;\n","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/526360e320da9d1b36074be5ed64fe76e5bbfbbd/server/utils/AiProviders/openAi/index.js#L132-L168","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before - non-gpt id that 404s on models.retrieve\nOPEN_MODEL_PREF=my-custom-ft-model\n\n// after - use an accessible id or a gpt- prefix short-circuit\nOPEN_MODEL_PREF=gpt-4.1-mini","handlingStrategy":"validation","validationCode":"const isAccessibleOpenAiModel = async (openai, model) => {\n  if (model.toLowerCase().includes('gpt') || model.toLowerCase().startsWith('o')) return true;\n  try { await openai.models.retrieve(model); return true; } catch { return false; }\n};\nif (!(await isAccessibleOpenAiModel(openai, modelId)))\n  throw new Error(`OpenAI model '${modelId}' is not accessible with this key.`);","typeGuard":"const isPresetOpenAiModel = (m) =>\n  typeof m === 'string' && (m.toLowerCase().includes('gpt') || m.toLowerCase().startsWith('o'));","tryCatchPattern":null,"preventionTips":["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."],"tags":["openai","configuration","validation"],"backgroundTag":null,"analyzedSha":"526360e320da9d1b36074be5ed64fe76e5bbfbbd","analyzedAt":"2026-08-13T01:45:47.170Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}