{"record":{"id":"ce28973300ee3eb9","repo":"Significant-Gravitas/AutoGPT","slug":"codex-credential-not-allowed","errorCode":null,"errorMessage":"codex_credential_not_allowed","messagePattern":"codex_credential_not_allowed","errorType":"http","errorClass":"HTTPException","httpStatus":422,"severity":"warning","filePath":"autogpt_platform/backend/backend/api/features/chat/routes.py","lineNumber":588,"sourceCode":"            raise HTTPException(\n                status_code=422,\n                detail=\"codex_builder_session_unsupported\",\n            )\n        if not _is_deployment_chat_available():\n            raise HTTPException(\n                status_code=503,\n                detail=\"chat_transport_not_configured\",\n            )\n        return \"platform\", None\n\n    transports = await _get_chat_transports(user_id)\n    if request is not None:\n        route_was_explicit = bool(\n            {\"llm_auth_provider\", \"llm_credential_id\"} & request.model_fields_set\n        )\n        if route_was_explicit:\n            if auth_provider == \"platform\" and credential_id is not None:\n                raise HTTPException(\n                    status_code=422,\n                    detail=\"codex_credential_not_allowed\",\n                )\n            if auth_provider == \"codex\" and credential_id is None:\n                raise HTTPException(\n                    status_code=422,\n                    detail=\"codex_credential_required\",\n                )\n            selected_route = next(\n                (\n                    transport\n                    for transport in transports\n                    if transport.auth_provider == auth_provider\n                    and transport.credential_id == credential_id\n                    and transport.available\n                ),\n                None,\n            )","sourceCodeStart":570,"sourceCodeEnd":606,"githubUrl":"https://github.com/Significant-Gravitas/AutoGPT/blob/9c8bb5550f446ba5d3046b78896578742495b3cf/autogpt_platform/backend/backend/api/features/chat/routes.py#L570-L606","documentation":"A 422 from _resolve_new_session_llm_route: the client explicitly set llm_auth_provider='platform' (or omitted the provider but explicitly set llm_credential_id) in the create-session request. Credentials are a codex-route concept; the platform route is credential-less, so pairing a credential with it is rejected rather than silently ignored.","triggerScenarios":"POST /chat/sessions with {\"llm_auth_provider\": \"platform\", \"llm_credential_id\": \"...\"}, or a body that includes only llm_credential_id (provider defaults to 'platform'). The check fires only when either routing field was explicitly sent (model_fields_set), not when defaults apply.","commonSituations":"Client reuses one form/model for both routes and always serializes llm_credential_id (e.g. null-to-empty-string coercion); user switches provider dropdown back to 'platform' after picking a credential and the stale credential stays in the payload.","solutions":["Send llm_credential_id only when llm_auth_provider is 'codex'; omit it (do not send null) for platform sessions.","Clear the credential field in the client's state whenever the provider selection changes to 'platform'.","If using a shared request builder, make credential inclusion conditional rather than unconditional."],"exampleFix":"// before\n{llm_auth_provider: provider, llm_credential_id: credId ?? undefined}  // credId sent even for 'platform'\n\n// after\n{llm_auth_provider: provider, ...(provider === 'codex' ? {llm_credential_id: credId} : {})}","handlingStrategy":"validation","validationCode":"const body = provider === 'codex'\n  ? {llm_auth_provider: provider, llm_credential_id: credId}\n  : {llm_auth_provider: provider}; // no credential key at all\nawait createSession(body);","typeGuard":"function isCoherentRoute(provider: string, credId?: string): boolean {\n  return provider === 'codex' ? credId != null : credId == null;\n}","tryCatchPattern":null,"preventionTips":["Make credential inclusion conditional on provider, not always-serialized.","Reset credential state when the provider dropdown changes.","Prefer omitting optional keys over sending null — the backend checks model_fields_set."],"tags":["backend","chat","codex","session-creation","http-422"],"backgroundTag":null,"analyzedSha":"9c8bb5550f446ba5d3046b78896578742495b3cf","analyzedAt":"2026-08-14T17:17:21.957Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}