BerriAI/litellm · critical · HTTPException
Prompt '{prompt_id}' not found
Error message
Prompt '{prompt_id}' not found What it means
The client-resolution guard on the retrieve path: retrieve_fine_tuning_job builds a client via get_openai_client(); if it returns None (no api_key argument, no OPENAI_API_KEY environment/secret value, no custom client), this ValueError is raised before any HTTP request. It is a missing-credentials error, local to litellm.
Source
Thrown at cookbook/mock_prompt_management_server/mock_prompt_management_server.py:303
return {"prompts": prompts_list, "total": len(prompts_list)}
@app.get("/prompts/{prompt_id}/variables")
async def get_prompt_variables(
prompt_id: str, authorization: Optional[str] = Header(None)
):
"""
Get all variables in a prompt template.
This is a convenience endpoint (not part of the LiteLLM spec) for
discovering what variables a prompt expects.
"""
# Verify authentication
verify_api_key(authorization)
if prompt_id not in PROMPTS_DB:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Prompt '{prompt_id}' not found",
)
prompt_data = PROMPTS_DB[prompt_id]
variables = set()
# Extract variables from the prompt template
import re
for message in prompt_data["prompt_template"]:
content = message.get("content", "")
# Find all {variable} patterns
found_vars = re.findall(r"\{(\w+)\}", content)
variables.update(found_vars)
return {
"prompt_id": prompt_id,View on GitHub (pinned to 6c2dcb801b)
Solutions
- Ensure OPENAI_API_KEY is exported in the polling process.
- Or pass api_key=... to retrieve_fine_tuning_job.
- Or pass a prebuilt client via client=.
Example fix
# before job = litellm.retrieve_fine_tuning_job(fine_tuning_job_id="ftjob-abc") # after job = litellm.retrieve_fine_tuning_job(fine_tuning_job_id="ftjob-abc", api_key=os.environ["OPENAI_API_KEY"])
Defensive patterns
Strategy: validation
Validate before calling
import os
def can_retrieve_jobs(api_key: str | None) -> bool:
return bool(api_key or os.environ.get("OPENAI_API_KEY")) Try / catch
try:
job = litellm.retrieve_fine_tuning_job(fine_tuning_job_id=jid)
except ValueError as e:
if "not initialized" in str(e):
job = litellm.retrieve_fine_tuning_job(fine_tuning_job_id=jid, api_key=os.environ["OPENAI_API_KEY"])
else:
raise Prevention
- Schedulers (cron/Airflow) need the env var explicitly; verify with `env | grep OPENAI` in the job.
- Pass api_key explicitly in status-polling code.
When it happens
Trigger: Calling litellm.retrieve_fine_tuning_job(fine_tuning_job_id=...) with no key in the call, module globals, or environment.
Common situations: Status-checking scripts run from schedulers (cron, Airflow) that lack the interactive shell's env; key present under a different variable name; secrets injected only into web processes, not the polling job.
Related errors
- Missing Authorization header
- Invalid bearer token
- Invalid API key
- Error: {response.status_code} - {response.text}
- Invalid Authorization header format. Expected: Bearer <token
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/42ab44b458bec076.
Report an issue: GitHub.