{"record":{"id":"cc836e576061be07","repo":"Mintplex-Labs/anything-llm","slug":"fireworksai-chat-this-model-is-not-valid-for-c","errorCode":null,"errorMessage":"FireworksAI chat: ${this.model} is not valid for chat completion!","messagePattern":"FireworksAI chat: (.+?) is not valid for chat completion!","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"server/utils/AiProviders/fireworksAi/index.js","lineNumber":140,"sourceCode":"    return availableModels.hasOwnProperty(model);\n  }\n\n  constructPrompt({\n    systemPrompt = \"\",\n    contextTexts = [],\n    chatHistory = [],\n    userPrompt = \"\",\n  }) {\n    const prompt = {\n      role: \"system\",\n      content: `${systemPrompt}${this.#appendContext(contextTexts)}`,\n    };\n    return [prompt, ...chatHistory, { role: \"user\", content: userPrompt }];\n  }\n\n  async getChatCompletion(messages = null, { temperature = 0.7 }) {\n    if (!(await this.isValidChatCompletionModel(this.model)))\n      throw new Error(\n        `FireworksAI chat: ${this.model} is not valid for chat completion!`\n      );\n\n    const result = await LLMPerformanceMonitor.measureAsyncFunction(\n      this.openai.chat.completions.create({\n        model: this.model,\n        messages,\n        temperature,\n      })\n    );\n\n    if (\n      !result.output.hasOwnProperty(\"choices\") ||\n      result.output.choices.length === 0\n    )\n      return null;\n\n    return {","sourceCodeStart":122,"sourceCodeEnd":158,"githubUrl":"https://github.com/Mintplex-Labs/anything-llm/blob/3aec848f2885144aa8f1e53b9731a04310d5d558/server/utils/AiProviders/fireworksAi/index.js#L122-L158","documentation":"FireworksAiLLM.getChatCompletion validates this.model against the locally cached Fireworks catalog (storage/models/fireworks/models.json, refreshed via #syncModels) before sending a request. If the model id is not a key in that catalog, the request is rejected pre-flight with this error. This mirrors the streaming guard at line 175 and exists because Fireworks would otherwise return an opaque 404 from its inference API.","triggerScenarios":"getChatCompletion() called with this.model set to an id that is not in models.json — e.g. a deprecated/renamed model, a typo in FIREWORKS_AI_LLM_MODEL_PREF or the workspace modelPreference, or a catalog that is stale because the cache file could not be refreshed (offline server, read-only storage) and predates the model you selected.","commonSituations":"Fireworks deprecates or renames a model after you pinned it in a workspace; a hand-edited models.json cache is stale; the server had no network when the cache was last written so newer models never appeared; modelPreference passed from the UI contains extra whitespace or wrong casing.","solutions":["Set the model to a currently served Fireworks id (e.g. accounts/fireworks/models/llama-v3p1-8b-instruct) via the workspace model preference or FIREWORKS_AI_LLM_MODEL_PREF","Delete the stale cache (storage/models/fireworks/models.json and .cached_at) and retry so #syncModels refetches the live catalog","Check the exact id casing/whitespace in the saved preference — the check is a plain object-key lookup, so exact match is required","List valid ids with a direct call: curl -H \"Authorization: Bearer $FIREWORKS_AI_LLM_API_KEY\" https://api.fireworks.ai/inference/v1/models"],"exampleFix":"// before\nthis.model = \"llama-3.1-8b\"; // not a real catalog id\n\n// after\nthis.model = \"accounts/fireworks/models/llama-v3p1-8b-instruct\";","handlingStrategy":"validation","validationCode":"// use the provider's own catalog check before sending the real prompt\nconst ok = await llm.isValidChatCompletionModel(llm.model);\nif (!ok) {\n  const available = Object.keys(llm.models());\n  return respond(`Model '${llm.model}' unavailable. Pick from: ${available.join(\", \")}`);\n}\nawait llm.getChatCompletion(messages);","typeGuard":null,"tryCatchPattern":"try {\n  await llm.getChatCompletion(messages);\n} catch (err) {\n  if (err.message.includes(\"is not valid for chat completion\")) {\n    // refresh catalog + prompt re-selection; do not blind-retry\n    fs.rmSync(\"storage/models/fireworks/models.json\", { force: true });\n    return respond(\"Model no longer available — pick another FireworksAI model.\");\n  }\n  throw err;\n}","preventionTips":["Run isValidChatCompletionModel before the first chat of a session and cache the verdict","Refresh the models.json cache on a schedule or on provider-config change","Pin model ids from the API's /models listing, not from documentation that may be stale"],"tags":["fireworks-ai","invalid-model-name","model-catalog","pre-flight-check"],"backgroundTag":"invalid-model-name","analyzedSha":"3aec848f2885144aa8f1e53b9731a04310d5d558","analyzedAt":"2026-08-18T10:02:21.017Z","contentChangedAt":"2026-08-18T10:02:21.017Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}