chroma-core/chroma · error · ValueError
Missing 'api_key_env_var' or 'api_base' in configuration for
Error message
Missing 'api_key_env_var' or 'api_base' in configuration for BasetenEmbeddingFunction.
What it means
When a "baseten" embedding function is rebuilt from a persisted config, build_from_config requires both the "api_key_env_var" and "api_base" keys to be present (non-None); if either is missing it raises this ValueError naming both. Note that ef.get_config() always returns both keys, so a faithful round-trip never fails — the error indicates a hand-written, edited, or schema-drifted config dict.
Source
Thrown at chromadb/utils/embedding_functions/baseten_embedding_function.py:87
def get_config(self) -> Dict[str, Any]:
return {"api_base": self.api_base, "api_key_env_var": self.api_key_env_var}
@staticmethod
def build_from_config(config: Dict[str, Any]) -> "BasetenEmbeddingFunction":
"""
Build the BasetenEmbeddingFunction from a configuration dictionary.
Args:
config (Dict[str, Any]): A dictionary containing the configuration parameters.
Expected keys: 'api_key', 'api_base', 'api_key_env_var'.
Returns:
BasetenEmbeddingFunction: An instance of BasetenEmbeddingFunction.
"""
api_key_env_var = config.get("api_key_env_var")
api_base = config.get("api_base")
if api_key_env_var is None or api_base is None:
raise ValueError(
"Missing 'api_key_env_var' or 'api_base' in configuration for BasetenEmbeddingFunction."
)
# Note: We rely on the __init__ method to handle potential missing api_key
# by checking the environment variable if the config value is None.
# However, api_base must be present either in config or have a default.
if api_base is None:
raise ValueError(
"Missing 'api_base' in configuration for BasetenEmbeddingFunction."
)
return BasetenEmbeddingFunction(
api_key=None, # Pass None if not in config, __init__ will check env var
api_base=api_base,
api_key_env_var=api_key_env_var,
)
@staticmethodView on GitHub (pinned to aecdd12c8a)
Solutions
- Always generate the config via ef.get_config() and re-attach the name — it emits exactly the keys build_from_config expects.
- If hand-writing, include both: {"name": "baseten", "config": {"api_base": "https://...", "api_key_env_var": "CHROMA_BASETEN_API_KEY"}}.
- Validate the two required keys before calling and raise your own descriptive error.
Example fix
# before: ValueError "Missing 'api_key_env_var' or 'api_base' in configuration for BasetenEmbeddingFunction."
ef = config_to_embedding_function({"name": "baseten", "config": {"api_base": "https://app.baseten.co/..."}})
# after
ef = config_to_embedding_function({
"name": "baseten",
"config": {"api_base": "https://app.baseten.co/...", "api_key_env_var": "CHROMA_BASETEN_API_KEY"},
}) Defensive patterns
Strategy: validation
Validate before calling
REQUIRED = {"api_key_env_var", "api_base"}
def validate_baseten_config(cfg: dict) -> None:
missing = REQUIRED - set(cfg)
if missing:
raise ValueError(f"baseten config missing required keys: {sorted(missing)}")
validate_baseten_config(inner_cfg)
ef = config_to_embedding_function({"name": "baseten", "config": inner_cfg}) Type guard
def is_complete_baseten_config(cfg: object) -> bool:
return (
isinstance(cfg, dict)
and isinstance(cfg.get("api_base"), str)
and isinstance(cfg.get("api_key_env_var"), str)
) Try / catch
from chromadb.utils.embedding_functions import config_to_embedding_function
try:
ef = config_to_embedding_function(cfg)
except ValueError as e:
if "Missing 'api_key_env_var' or 'api_base'" in str(e):
cfg.setdefault("config", {}).setdefault("api_key_env_var", "CHROMA_BASETEN_API_KEY")
ef = config_to_embedding_function(cfg) # api_base still required from real config
else:
raise Prevention
- Round-trip configs through ef.get_config() instead of authoring them by hand.
- Validate required keys at the boundary where configs enter your system (API payload, job queue).
- Add contract tests that build_from_config accepts everything get_config emits.
When it happens
Trigger: config_to_embedding_function({"name": "baseten", "config": {"api_base": "..."}}) with api_key_env_var absent (or vice versa); configs from older versions or external stores missing the key.
Common situations: Hand-assembled config dicts; JSON configs edited by hand where one key was dropped; migrating persisted collection metadata between systems that trimmed fields.
Related errors
- Config must contain a 'name' field.
- Missing 'api_base' in configuration for BasetenEmbeddingFunc
- Unsupported embedding function: {name}
- The boto3 python package is not installed. Please install it
- The openai python package is not installed. Please install i
AI-assisted analysis of chroma-core/chroma@aecdd12c8a (2026-08-16).
Data as JSON: /api/errors/064503d854b0bc5f.
Report an issue: GitHub.