{"record":{"id":"dfe50c108ae474e1","repo":"BoundaryML/baml","slug":"bamlerror-bamlclienterror-something-went-wrong-with-the-llm","errorCode":null,"errorMessage":"BamlError: BamlClientError: Something went wrong with the LLM client: {failed.message}","messagePattern":"BamlError: BamlClientError: Something went wrong with the LLM client: (.+?)","errorType":"exception","errorClass":"BamlClientError","httpStatus":null,"severity":"error","filePath":"engine/language_client_typescript/src/errors.rs","lineNumber":92,"sourceCode":"                None\n            } else {\n                Some(detailed_message.as_str())\n            }),\n            ExposedError::TimeoutError {\n                client_name,\n                message,\n            } => throw_baml_timeout_error(client_name, message),\n        }\n    } else if let Some(er) = err.downcast_ref::<ScopeStack>() {\n        invalid_argument_error(&format!(\"{er}\"))\n    } else if let Some(er) = err.downcast_ref::<LLMResponse>() {\n        match er {\n            LLMResponse::Success(_) => napi::Error::new(\n                napi::Status::GenericFailure,\n                format!(\"BamlError: Unexpected error from BAML: {err}\"),\n            ),\n            LLMResponse::LLMFailure(failed) => match &failed.code {\n                baml_runtime::internal::llm_client::ErrorCode::Other(2) => napi::Error::new(\n                    napi::Status::GenericFailure,\n                    format!(\n                        \"BamlError: BamlClientError: Something went wrong with the LLM client: {}\",\n                        failed.message\n                    ),\n                ),\n                baml_runtime::internal::llm_client::ErrorCode::Timeout => {\n                    throw_baml_timeout_error(failed.client.as_str(), failed.message.as_str())\n                }\n                baml_runtime::internal::llm_client::ErrorCode::Other(_)\n                | baml_runtime::internal::llm_client::ErrorCode::InvalidAuthentication\n                | baml_runtime::internal::llm_client::ErrorCode::NotSupported\n                | baml_runtime::internal::llm_client::ErrorCode::RateLimited\n                | baml_runtime::internal::llm_client::ErrorCode::ServerError\n                | baml_runtime::internal::llm_client::ErrorCode::ServiceUnavailable\n                | baml_runtime::internal::llm_client::ErrorCode::UnsupportedResponse(_) => {\n                    throw_baml_client_http_error(\n                        failed.client.as_str(),","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_typescript/src/errors.rs#L74-L110","documentation":"When from_anyhow_error sees LLMResponse::LLMFailure with code ErrorCode::Other(2), it maps it to 'BamlError: BamlClientError: Something went wrong with the LLM client: <failed.message>'. This is BAML's BamlClientError family: the LLM provider call itself failed (auth, network, bad request, provider-side error).","triggerScenarios":"A b.FunctionName() call whose LLM round-trip failed: invalid API key, exhausted quota/rate limit, unreachable provider, malformed request the provider rejected, or retry strategy exhausted.","commonSituations":"Missing/rotated OPENAI_API_KEY / ANTHROPIC_API_KEY env vars; wrong model name in the client config; network blocked in CI; provider 4xx/5xx responses after BAML's retry policy gives up.","solutions":["Read failed.message / the message suffix for the provider's reason (401 auth, 429 rate limit, model not found).","Verify the provider API key env var is set and valid for the configured client.","Check the client config in .baml (model name, base_url, api_key) for typos.","Add a retry policy to the client in .baml for transient failures, and/or catch BamlClientError in JS to degrade gracefully."],"exampleFix":"// .baml, before\nclient Gpt4 {\n  provider openai\n  model gpt-4o-mini\n}\n// after\nclient Gpt4 {\n  provider openai\n  model gpt-4o-mini\n  options {\n    api_key env.OPENAI_API_KEY\n    max_retries 3\n  }\n}","handlingStrategy":"retry","validationCode":"if (!process.env.OPENAI_API_KEY && clientUsesOpenAI) throw new Error('OPENAI_API_KEY not set before BAML call');","typeGuard":"function isBamlClientError(e: unknown): e is Error {\n  return e instanceof Error && e.message.startsWith('BamlError: BamlClientError:');\n}","tryCatchPattern":"try {\n  const res = await b.MyFunction(input);\n} catch (e) {\n  if (isBamlClientError(e)) {\n    if (e.message.includes('429')) await sleep(backoff++ * 1000).then(() => retry());\n    else if (e.message.includes('401')) notifyOps('Bad LLM API key');\n    else throw e;\n  } else throw e;\n}","preventionTips":["Set provider API keys as env vars and assert them at startup.","Add a retry policy (max_retries, backoff) to LLM clients in .baml.","Validate model names and base_url against the provider's current catalog.","Catch BamlClientError at call sites and fall back to another client."],"tags":["rust","napi","llm","client-error","api"],"backgroundTag":"api-error-response","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"}