{"record":{"id":"9031e43c8bbcc2ed","repo":"BoundaryML/baml","slug":"when-using-openai-generic-you-must-specify-a-base-url","errorCode":null,"errorMessage":"When using 'openai-generic', you must specify a base_url","messagePattern":"When using 'openai-generic', you must specify a base_url","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/generic.rs","lineNumber":21,"sourceCode":"use anyhow::{Context, Result};\n\nuse crate::{\n    internal::llm_client::{properties_hander::PropertiesHandler, AllowedMetadata},\n    RuntimeContext,\n};\n\nuse super::PostRequestProperties;\n\npub fn resolve_properties(\n    mut properties: PropertiesHandler,\n    ctx: &RuntimeContext,\n) -> Result<PostRequestProperties> {\n    let default_role = properties.pull_default_role(\"system\")?;\n\n    let base_url = properties.pull_base_url()?;\n    let base_url = match base_url {\n        Some(base_url) => base_url,\n        None => anyhow::bail!(\"When using 'openai-generic', you must specify a base_url\"),\n    };\n    let allowed_metadata = properties.pull_allowed_role_metadata()?;\n\n    let headers = properties.pull_headers()?;\n    let api_key = match properties.pull_api_key()? {\n        Some(api_key) if !api_key.is_empty() => Some(api_key),\n        _ => None,\n    };\n    let supported_request_modes = properties.pull_supported_request_modes()?;\n\n    let properties = properties.finalize();\n\n    Ok(PostRequestProperties {\n        default_role,\n        base_url,\n        api_key,\n        headers,\n        properties,","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/baml-runtime/src/internal/llm_client/primitive/openai/properties/generic.rs#L3-L39","documentation":"The `openai-generic` provider is designed to talk to arbitrary OpenAI-compatible endpoints, so unlike the named providers it has no default host. resolve_properties requires a `base_url` option; if it is absent or null, the client cannot know where to send requests and bails with this error.","triggerScenarios":"Declaring a client with provider `openai-generic` in BAML without a `base_url` in its options block, or setting base_url via an expression that evaluates to null/empty (e.g. env.BASE_URL with the env var unset).","commonSituations":"Pointing BAML at a self-hosted or third-party OpenAI-compatible server (vLLM, Ollama, LiteLLM) and forgetting the endpoint; renaming an env var so the interpolated base_url becomes empty; copying an `openai` client config and switching only the provider string.","solutions":["Add `base_url` to the openai-generic client options (e.g. base_url \"http://localhost:8000/v1\").","If base_url comes from an env var, confirm the variable is set in the runtime environment.","If you actually meant the real OpenAI API, switch the provider to `openai` which has a default endpoint."],"exampleFix":"// before\nclient<MyGeneric> {\n  provider openai-generic\n  options {\n    api_key env.MY_KEY\n  }\n}\n// after\nclient<MyGeneric> {\n  provider openai-generic\n  options {\n    base_url \"http://localhost:11434/v1\"\n    api_key env.MY_KEY\n  }\n}","handlingStrategy":"validation","validationCode":"// baml-cli check, or in code:\nif client.provider == \"openai-generic\" && (client.options.base_url == null || client.options.base_url.isEmpty()) {\n    throw new Error(\"openai-generic requires a non-empty base_url in options\");\n}","typeGuard":null,"tryCatchPattern":"// Rust/anyhow caller\nmatch baml_runtime::run(fn_name, params) {\n    Ok(res) => res,\n    Err(e) if e.to_string().contains(\"must specify a base_url\") => {\n        eprintln!(\"openai-generic client misconfigured: set base_url (check env vars)\");\n        std::process::exit(2);\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Always include base_url in every openai-generic client block.","Run `baml-cli check` (or the VSCode extension diagnostics) after editing clients.baml.","When interpolating env vars into base_url, verify the env var exists in all deployment environments."],"tags":["openai","config","base-url","baml"],"backgroundTag":"missing-required-config-field","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"}