Mintplex-Labs/anything-llm · error · Error

GroqAI:streamChatCompletion: ${this.model} is not valid for

Error message

GroqAI:streamChatCompletion: ${this.model} is not valid for chat completion!

What it means

Identical guard to the non-streaming Groq path but at the top of streamGetChatCompletion. It throws when isValidChatCompletionModel(this.model) is false — a model not in MODEL_MAP — before opening the streaming request.

Source

Thrown at server/utils/AiProviders/groq/index.js:216

      textResponse: result.output.choices[0].message.content,
      metrics: {
        prompt_tokens: result.output.usage.prompt_tokens || 0,
        completion_tokens: result.output.usage.completion_tokens || 0,
        total_tokens: result.output.usage.total_tokens || 0,
        outputTps:
          result.output.usage.completion_tokens /
          result.output.usage.completion_time,
        duration: result.output.usage.total_time,
        model: this.model,
        provider: this.className,
        timestamp: new Date(),
      },
    };
  }

  async streamGetChatCompletion(messages = null, { temperature = 0.7 }) {
    if (!(await this.isValidChatCompletionModel(this.model)))
      throw new Error(
        `GroqAI:streamChatCompletion: ${this.model} is not valid for chat completion!`
      );

    const measuredStreamRequest = await LLMPerformanceMonitor.measureStream({
      func: this.openai.chat.completions.create({
        model: this.model,
        stream: true,
        messages,
        temperature,
      }),
      messages,
      runPromptTokenCalculation: false,
      modelTag: this.model,
      provider: this.className,
    });

    return measuredStreamRequest;
  }

View on GitHub (pinned to 526360e320)

Solutions

  1. Set GROQ_MODEL_PREF to an id present in GET /v1/models
  2. Update server/utils/AiProviders/modelMap.js MODEL_MAP for new models
  3. Pass a valid modelPreference at construction
  4. Restart the server after the change

Example fix

// before
// .env: GROQ_MODEL_PREF=llama2-70b-chat   // not in MODEL_MAP

// after
// .env: GROQ_MODEL_PREF=llama-3.1-8b-instant
Defensive patterns

Strategy: validation

Validate before calling

const valid = await groqLlm.isValidChatCompletionModel(model);
if (!valid) {
  throw new ConfigError(`Model '${model}' is not valid for Groq streaming.`);
}

Type guard

const isStreamableGroqModel = (id, MODEL_MAP) =>
  Object.values(MODEL_MAP).flat().includes(id);

Prevention

When it happens

Trigger: Calling streamGetChatCompletion with a this.model that is absent from Groq's MODEL_MAP: deprecated id, typo, or a model not yet added to AnythingLLM's map.

Common situations: GROQ_MODEL_PREF pointing at a model Groq removed; UI saved a model id that was later renamed; streaming a brand-new model before updating modelMap.js.

Related errors


AI-assisted analysis of Mintplex-Labs/anything-llm@526360e320 (2026-08-13). Data as JSON: /api/errors/a99b787b3bfd7c8a. Report an issue: GitHub.