{"record":{"id":"667caa3773004363","repo":"BoundaryML/baml","slug":"llm-client-client-name-requires-environment-variable-key-to","errorCode":null,"errorMessage":"LLM client '{client_name}' requires environment variable '{key}' to be set but it is not","messagePattern":"LLM client '(.+?)' requires environment variable '(.+?)' to be set but it is not","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/lib.rs","lineNumber":1951,"sourceCode":"                // env vars because the proxy server is likely to provide them.\n                let fail_on_missing_required_env_vars = !ctx.is_modular_api()\n                    && !uses_proxy_server\n                    && !matches!(\n                        walker.item.elem.provider,\n                        internal_llm_client::ClientProvider::AwsBedrock\n                            | internal_llm_client::ClientProvider::Vertex\n                    );\n\n                for key in walker.required_env_vars() {\n                    if let Some(value) = ctx.env_vars().get(&key) {\n                        if fail_on_missing_required_env_vars && value.trim().is_empty() {\n                            baml_log::warn!(\n                                \"Required environment variable '{key}' for client '{client_name}' is set but is empty: {key}='{value}'\"\n                            );\n                        }\n                        required_env_vars.insert(key, value.to_owned());\n                    } else if fail_on_missing_required_env_vars {\n                        anyhow::bail!(\n                            \"LLM client '{client_name}' requires environment variable '{key}' to be set but it is not\"\n                        );\n                    }\n                }\n\n                // Also include BOUNDARY_* env vars if they exist, for tracing/telemetry\n                if let Some(boundary_api_key) = ctx.env_vars().get(\"BOUNDARY_API_KEY\") {\n                    required_env_vars\n                        .insert(\"BOUNDARY_API_KEY\".to_string(), boundary_api_key.to_owned());\n                }\n                if let Some(boundary_api_url) = ctx.env_vars().get(\"BOUNDARY_API_URL\") {\n                    required_env_vars\n                        .insert(\"BOUNDARY_API_URL\".to_string(), boundary_api_url.to_owned());\n                }\n\n                clients.insert(\n                    client_name.into(),\n                    runtime::CachedClient::new(new_client.clone(), required_env_vars),","sourceCodeStart":1933,"sourceCodeEnd":1969,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/lib.rs#L1933-L1969","documentation":"When loading clients, BAML collects the environment variables that each LLM client's provider config requires (declared via env_variable or referenced provider config). If a required variable is absent from the environment and fail_on_missing_required_env_vars is true, the runtime bails with this error naming the client and the missing key. It prevents constructing API clients that would inevitably fail at request time with an auth error.","triggerScenarios":"Calling BamlRuntime load / client setup (e.g. `baml-cli dev`, runtime.load_src, LoadSrcArgs) where a client like `provider \"openai\" { api_key env.OPENAI_API_KEY }` references an env var that is unset, while fail_on_missing_required_env_vars is enabled.","commonSituations":"Deploying to a server/CI where the .env file isn't copied; forgetting to export the key in the shell; typo in the variable name between generators.baml and the environment; secrets not injected into a container/serverless runtime.","solutions":["Export the required environment variable (e.g. `export OPENAI_API_KEY=sk-...`) or add it to your .env file before starting the app","Check the variable name in generators.baml matches the actual env var exactly (case-sensitive)","In CI/deployment, add the secret to the environment/secret manager (GitHub Actions secrets, Docker env, Lambda env vars)","Restart the dev server/shell after setting the variable so it's picked up"],"exampleFix":"// before\nBAML_SECRET_OPENAI_API_KEY= sk-  (missing in shell)\n\n// after\n# .env\nOPENAI_API_KEY=sk-...\n# then\nexport $(grep -v '^#' .env | xargs)","handlingStrategy":"validation","validationCode":"const required = ['OPENAI_API_KEY']; // keys referenced in generators.baml\nconst missing = required.filter((k) => !process.env[k]);\nif (missing.length) throw new Error(`Missing env vars before loading BAML: ${missing.join(', ')}`);","typeGuard":null,"tryCatchPattern":"try {\n  await bamlRuntime.loadSrc({ bamlSrc });\n} catch (e) {\n  const m = /requires environment variable '([^']+)'/i.exec(e.message);\n  if (m) throw new Error(`Set ${m[1]} in your environment (check .env and deployment secrets)`);\n  throw e;\n}","preventionTips":["Commit a .env.example listing every env var referenced in generators.baml","Load dotenv at process startup before initializing BAML","Add secret injection to every CI/deploy environment (GitHub Actions secrets, Docker env, serverless env vars)","Verify env var names in generators.baml are case-sensitive matches of the real variables"],"tags":["environment","configuration","api-key","baml"],"backgroundTag":"missing-env-var","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}