{"record":{"id":"33cf0a4b1cd0c928","repo":"wandb/openui","slug":"groq-api-key-is-not-set","errorCode":null,"errorMessage":"Groq API key is not set.","messagePattern":"Groq API key is not set\\.","errorType":"http","errorClass":"HTTPException","httpStatus":500,"severity":"error","filePath":"backend/openui/server.py","lineNumber":152,"sourceCode":"        if data.get(\"model\").startswith(\"gpt\"):\n            if data[\"model\"] == \"gpt-4\" or data[\"model\"] == \"gpt-4-32k\":\n                raise HTTPException(status=400, data=\"Model not supported\")\n            response: AsyncStream[\n                ChatCompletionChunk\n            ] = await openai.chat.completions.create(\n                **data,\n            )\n            # gpt-4 tokens are 20x more expensive\n            multiplier = 20 if \"gpt-4\" in data[\"model\"] else 1\n            return StreamingResponse(\n                openai_stream_generator(response, input_tokens, user_id, multiplier),\n                media_type=\"text/event-stream\",\n            )\n        # Groq Models\n        elif data.get(\"model\").startswith(\"groq/\"):\n            data[\"model\"] = data[\"model\"].replace(\"groq/\", \"\")\n            if groq is None:\n                raise HTTPException(status=500, detail=\"Groq API key is not set.\")\n            response: AsyncStream[\n                ChatCompletionChunk\n            ] = await groq.chat.completions.create(\n                **data,\n            )\n            return StreamingResponse(\n                openai_stream_generator(response, input_tokens, user_id, 1),\n                media_type=\"text/event-stream\",\n            )\n        # Litellm Models\n        elif data.get(\"model\").startswith(\"litellm/\"):\n            data[\"model\"] = data[\"model\"].replace(\"litellm/\", \"\")\n            if litellm is None:\n                raise HTTPException(status=500, detail=\"LiteLLM API key is not set.\")\n            response: AsyncStream[\n                ChatCompletionChunk\n            ] = await litellm.chat.completions.create(\n                **data,","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/wandb/openui/blob/42d7ab4ab6650433486dfb12eb3783c393a3e475/backend/openui/server.py#L134-L170","documentation":"This error is raised by OpenUI's chat_completions endpoint when a request targets a model prefixed with 'groq/' but the Groq client was never initialized because the GROQ_API_KEY environment variable was not set at startup. The endpoint checks `if groq is None` and aborts with HTTP 500 before calling the Groq API. It is a server-side configuration error, not an API error from Groq itself.","triggerScenarios":"POSTing to /chat/completions with data.model starting with 'groq/' (e.g. 'groq/llama3-70b-8192') while the server process was started without GROQ_API_KEY set, so the module-level groq client is None.","commonSituations":"Deploying OpenUI without configuring the Groq key in the environment (.env not loaded, key omitted in docker-compose or k8s secrets), switching to a Groq model after deploying with only other providers' keys, or restarting a container that lost its env vars.","solutions":["Set the GROQ_API_KEY environment variable before starting the server (e.g. export GROQ_API_KEY=gsk_... or add it to .env) and restart OpenUI.","Verify the key is loaded in the running process (docker exec env | grep GROQ or print os.environ in a startup log) since the check happens at import time.","If you don't intend to use Groq, select a model from a provider whose key is configured instead of a groq/ prefixed model.","Get a key from console.groq.com if you don't have one and add it to your deployment secrets."],"exampleFix":"// before (start server without key -> 500)\npython -m uvicorn openui.server:app\n// after\nGROQ_API_KEY=gsk_yourkeyhere python -m uvicorn openui.server:app","handlingStrategy":"validation","validationCode":"import os\ndef ensure_groq_ready():\n    if not os.environ.get(\"GROQ_API_KEY\"):\n        raise RuntimeError(\"GROQ_API_KEY is not set; groq/ models are unavailable\")\n# call before issuing any groq/ model request","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep all provider keys in one .env / secret manifest checked at startup","Fail fast: assert required env vars at server boot, not first request","Document per-provider key requirements next to model selection UI","Pin provider config in deployment templates (docker-compose, k8s secrets)"],"tags":["http-500","api-key","configuration","groq","fastapi"],"backgroundTag":"missing-env-var","analyzedSha":"42d7ab4ab6650433486dfb12eb3783c393a3e475","analyzedAt":"2026-09-01T05:00:32.200Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}