{"record":{"id":"801b02a715191406","repo":"Significant-Gravitas/AutoGPT","slug":"invalid-replicate-api-token","errorCode":null,"errorMessage":"Invalid Replicate API token","messagePattern":"Invalid Replicate API token","errorType":"exception","errorClass":"RuntimeError","httpStatus":500,"severity":"error","filePath":"autogpt_platform/backend/backend/api/features/store/image_gen.py","lineNumber":173,"sourceCode":"                else:\n                    # If it's a URL string, fetch the image bytes\n                    result_url = output[0]\n                    response = await Requests().get(result_url)\n                    image_bytes = response.content\n            elif isinstance(output, FileOutput):\n                image_bytes = output.read()\n            elif isinstance(output, str):\n                # Output is a URL\n                response = await Requests().get(output)\n                image_bytes = response.content\n            else:\n                raise RuntimeError(\"Unexpected output format from the model.\")\n\n            return io.BytesIO(image_bytes)\n\n        except ReplicateError as e:\n            if e.status == 401:\n                raise RuntimeError(\"Invalid Replicate API token\") from e\n            raise RuntimeError(f\"Replicate API error: {str(e)}\") from e\n\n    except Exception as e:\n        logger.exception(\"Failed to generate agent image\")\n        raise RuntimeError(f\"Image generation failed: {str(e)}\")\n","sourceCodeStart":155,"sourceCodeEnd":179,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/store/image_gen.py#L155-L179","documentation":"RuntimeError translated from a ReplicateError with HTTP status 401 inside generate_agent_image_v1(). Replicate's API rejects the bearer token used by ReplicateClient — the key configured in settings.secrets.replicate_api_key is invalid, expired, or revoked.","triggerScenarios":"Agent-image generation where the configured REPLICATE_API_KEY is wrong (typo, truncated when copied, deleted from the Replicate account, or an environment placeholder never replaced). The 401 surfaces on the first prediction request.","commonSituations":"Rotated/revoked token not updated in deployment secrets; placeholder values from .env.default leaking to staging; key copied with whitespace or quotes.","solutions":["Verify the token atReplicate: `curl -H \"Authorization: Bearer $REPLICATE_API_KEY\" https://api.replicate.com/v1/account` should return 200.","If invalid, generate a new API token in Replicate account settings and update backend secrets/.env.","Redeploy/restart the backend so Settings() picks up the corrected value."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import httpx\n\nasync def replicate_token_valid(key: str) -> bool:\n    async with httpx.AsyncClient() as client:\n        r = await client.get(\n            \"https://api.replicate.com/v1/account\",\n            headers={\"Authorization\": f\"Bearer {key}\"},\n        )\n        return r.status_code == 200","typeGuard":null,"tryCatchPattern":"try:\n    image = await generate_agent_image_v1(agent)\nexcept RuntimeError as e:\n    if \"Invalid Replicate API token\" in str(e):\n        raise HTTPException(503, \"Image provider credentials rejected\") from e\n    raise","preventionTips":["Validate third-party tokens during deployment smoke tests, not at first user request.","Rotate keys via the deployment secret store and restart promptly after revocation."],"tags":["store","replicate","auth","api-key","image-generation"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}