{"record":{"id":"68b1df052acbfb90","repo":"srbhr/Resume-Matcher","slug":"llm-completion-failed-please-check-your-api-confi","errorCode":null,"errorMessage":"LLM completion failed. Please check your API configuration and try again.","messagePattern":"LLM completion failed\\. Please check your API configuration and try again\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"apps/backend/app/llm.py","lineNumber":810,"sourceCode":"        if config.reasoning_effort:\n            kwargs[\"reasoning_effort\"] = config.reasoning_effort\n\n        response = await router.acompletion(**kwargs)\n\n        content = _extract_choice_text(response.choices[0])\n        if not content:\n            raise ValueError(\"Empty response from LLM\")\n        # Strip thinking tags from reasoning models (deepseek-r1, qwq, etc.)\n        if \"<think>\" in content:\n            content = _strip_thinking_tags(content)\n            if not content:\n                raise ValueError(\"Response contained only thinking content, no output\")\n        return content\n    except Exception as e:\n        # Log the actual error server-side for debugging\n        logging.error(f\"LLM completion failed: {e}\", extra={\n                      \"model\": model_name})\n        raise ValueError(\n            \"LLM completion failed. Please check your API configuration and try again.\"\n        ) from e\n\n\ndef _supports_json_mode(model_name: str) -> bool:\n    \"\"\"Check if the model supports JSON mode via LiteLLM's model registry.\n\n    Queries LiteLLM's model info for every provider (including openai,\n    anthropic, etc.) so that capability is always determined from the\n    registry rather than a hardcoded provider list.\n\n    Ollama models support JSON mode natively (format=\"json\") but are\n    often not in LiteLLM's registry (custom/local models), so we\n    always return True for ollama.\n\n    Args:\n        model_name: LiteLLM-formatted model name (from get_model_name).\n    \"\"\"","sourceCodeStart":792,"sourceCodeEnd":828,"githubUrl":"https://github.com/srbhr/Resume-Matcher/blob/116f9cc3b00e1ac91734a6c2679bf41ea64a0edc/apps/backend/app/llm.py#L792-L828","documentation":"complete() in llm.py wraps every failure of the underlying LiteLLM completion call (network errors, auth errors, bad model names, empty/thinking-only responses) in a single generic ValueError. The real cause is logged server-side, but the client-facing message only tells you to check your API configuration.","triggerScenarios":"Any exception inside complete() — LLM provider HTTP error, invalid/missing API key, unsupported model_name, rate limit, timeout, or a response containing only <think> content with no output.","commonSituations":"Expired or absent provider API key env var; model name not registered with the provider; proxy/firewall blocking the endpoint; provider outage; reasoning model returning only thinking tags.","solutions":["Check the server logs for the 'LLM completion failed: ...' line — it contains the true underlying error","Verify the provider API key env var (e.g. OPENAI_API_KEY/ANTHROPIC_API_KEY) is set and valid","Confirm the configured model_name is correct and supported by your provider/LiteLLM registry","Test connectivity to the LLM endpoint and retry in case of a transient provider outage"],"exampleFix":"// before\nconst text = await complete(prompt, config); // throws generic ValueError\n// after\ntry {\n  const text = await complete(prompt, config);\n} catch (e) {\n  showUser('AI generation failed — please retry');\n  logServer(e); // real cause is already logged by llm.py\n}","handlingStrategy":"try-catch","validationCode":"import os\ndef llm_config_ready() -> bool:\n    key = os.getenv(\"OPENAI_API_KEY\") or os.getenv(\"ANTHROPIC_API_KEY\")\n    return bool(key) and bool(os.getenv(\"LLM_MODEL\"))","typeGuard":null,"tryCatchPattern":"try:\n    content = await complete(prompt, config=config)\nexcept ValueError as e:\n    logger.error(\"LLM call failed; see llm.py server log for root cause\")\n    return fallback_response(\"AI service temporarily unavailable, please retry\")","preventionTips":["Check server logs for 'LLM completion failed: ...' — the real cause is logged there","Validate API keys and model names at startup with a smoke-test call","Set alerts on provider error rates/outages","Prefer models whose names are verified against the LiteLLM registry"],"tags":["llm","api-configuration","backend","litellm"],"backgroundTag":"llm-completion-failed","analyzedSha":"116f9cc3b00e1ac91734a6c2679bf41ea64a0edc","analyzedAt":"2026-08-28T22:51:40.999Z","schemaVersion":2},"datasetVersion":"2026-08-29T02:17:18.158Z"}