Mintplex-Labs/anything-llm · critical · Error

AWS_BEDROCK_LLM_API_KEY is required for AWS Bedrock.

Error message

AWS_BEDROCK_LLM_API_KEY is required for AWS Bedrock.

What it means

Thrown by the AWSBedrockLLM constructor when process.env.AWS_BEDROCK_LLM_API_KEY is falsy. AnythingLLM's Bedrock provider authenticates via an API key (plus region) rather than the standard AWS sigv4 IAM flow, so the key is a hard precondition. It is the first of two Bedrock constructor guards.

Source

Thrown at server/utils/AiProviders/bedrock/index.js:31

class AWSBedrockLLM {
  noSystemPromptModels = [
    "amazon.titan-text-express-v1",
    "amazon.titan-text-lite-v1",
    "cohere.command-text-v14",
    "cohere.command-light-text-v14",
    "us.deepseek.r1-v1:0",
  ];

  noTemperatureModels = [
    "anthropic.claude-opus-4-7",
    "anthropic.claude-opus-4-8",
    "anthropic.claude-sonnet-5",
  ];

  constructor(embedder = null, modelPreference = null) {
    if (!process.env.AWS_BEDROCK_LLM_API_KEY)
      throw new Error("AWS_BEDROCK_LLM_API_KEY is required for AWS Bedrock.");
    if (!process.env.AWS_BEDROCK_LLM_REGION)
      throw new Error("AWS_BEDROCK_LLM_REGION is required for AWS Bedrock.");

    this.className = "AWSBedrockLLM";
    this.model =
      modelPreference || process.env.AWS_BEDROCK_LLM_MODEL_PREFERENCE;
    this.region = process.env.AWS_BEDROCK_LLM_REGION;

    const contextWindowLimit = this.promptWindowLimit();
    this.limits = {
      history: Math.floor(contextWindowLimit * 0.15),
      system: Math.floor(contextWindowLimit * 0.15),
      user: Math.floor(contextWindowLimit * 0.7),
    };

    this.openai = new OpenAIApi({
      apiKey: process.env.AWS_BEDROCK_LLM_API_KEY,
      baseURL: `https://bedrock-mantle.${this.region}.api.aws/v1`,

View on GitHub (pinned to 526360e320)

Solutions

  1. Set `AWS_BEDROCK_LLM_API_KEY=<your bedrock api key>` in .env and restart.
  2. Also set AWS_BEDROCK_LLM_REGION (next guard, error 172) at the same time to avoid the immediate follow-on throw.
  3. If you intended IAM/role-based auth, note this provider requires the API-key env vars — generate a Bedrock API key accordingly or adapt the provider.
  4. Re-save Bedrock credentials in the UI to persist both env vars.

Example fix

// before
// .env
AWS_BEDROCK_LLM_API_KEY=

// after
// .env
AWS_BEDROCK_LLM_API_KEY=<bedrock-key>
AWS_BEDROCK_LLM_REGION=us-east-1
Defensive patterns

Strategy: validation

Validate before calling

if (!process.env.AWS_BEDROCK_LLM_API_KEY) {
  throw new Error(
    "AWS_BEDROCK_LLM_API_KEY is missing. This provider authenticates with an API key, not IAM role creds."
  );
}
if (!process.env.AWS_BEDROCK_LLM_REGION) {
  throw new Error("AWS_BEDROCK_LLM_REGION is missing (e.g. us-east-1).");
}
const llm = new AWSBedrockLLM(embedder, modelPref);

Type guard

/** @param {unknown} v @returns {boolean} */
function isNonEmptyKey(v) {
  return typeof v === "string" && v.trim().length > 0;
}

Try / catch

try {
  const llm = new AWSBedrockLLM(embedder, modelPref);
} catch (e) {
  if (/AWS_BEDROCK_LLM_API_KEY is required/.test(e.message)) {
    return { ok: false, reason: "missing-bedrock-key" };
  }
  throw e;
}

Prevention

When it happens

Trigger: Constructing AWSBedrockLLM with AWS_BEDROCK_LLM_API_KEY unset. The constructor immediately reads the key, region, model, and computes context-window limits — all blocked if the key is missing.

Common situations: Bedrock selected but credentials not entered; assumption that AWS SDK picks up IAM role creds (this provider needs the explicit key env); env var misnamed vs AWS_BEDROCK_LLM_ACCESS_KEY; deploying to a new host without the env.

Related errors


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