unslothai/unsloth · error · CodexAuthError
ChatGPT connection requires authorization.
Error message
ChatGPT connection requires authorization.
What it means
Raised as CodexAuthError by resolve_access when load_oauth_bundle(provider_id) returns no persisted credentials. resolve_access is the gate every inference call passes through to obtain an access token, so hitting it means the ChatGPT/Codex provider was never connected (or was disconnected) on this installation.
Source
Thrown at studio/backend/core/inference/openai_codex_auth.py:814
if not record or record.get("marker") != marker:
return
credential_secrets.delete_secret(
credential_secrets.OPENAI_CODEX_OAUTH_FLOW_KIND,
provider_id,
)
async def resolve_access(
provider_id: str,
*,
force_refresh: bool = False,
expected_access_token: str | None = None,
) -> tuple[str, str]:
lock = _refresh_locks.setdefault(provider_id, asyncio.Lock())
async with lock:
bundle = load_oauth_bundle(provider_id)
if not bundle:
raise CodexAuthError("ChatGPT connection requires authorization.")
if bundle.get("reauthorization_required"):
raise CodexAuthError("ChatGPT authorization is no longer valid. Please reconnect.")
if not force_refresh and bundle["expires_at"] > time.time() + _REFRESH_SKEW_SECONDS:
return bundle["access_token"], bundle["account_id"]
# Multiple Studio workers may share the installation DB. Serialize with
# disconnect/delete and re-read so a completed refresh is reused.
async with provider_oauth_write_guard(provider_id):
bundle = load_oauth_bundle(provider_id)
if not bundle:
raise CodexAuthError("ChatGPT connection requires authorization.")
if expected_access_token is not None and not secrets.compare_digest(
bundle["access_token"], expected_access_token
):
return bundle["access_token"], bundle["account_id"]
if not force_refresh and bundle["expires_at"] > time.time() + _REFRESH_SKEW_SECONDS:View on GitHub (pinned to 203007d190)
Solutions
- Complete the ChatGPT connection flow (browser or device) for this provider, then retry.
- Verify the provider_id passed to resolve_access matches the one used at connect time.
- Confirm all Studio workers share one installation DB so credentials are visible everywhere.
- In the UI, gate inference actions behind connection status (get_oauth_status) instead of letting unconfigured calls through.
Example fix
// before
try:
token, account = await resolve_access(provider_id)
except CodexAuthError:
raise # surfaced as a crash to the user
// after
try:
token, account = await resolve_access(provider_id)
except CodexAuthError as exc:
if "requires authorization" in str(exc):
return RedirectResponse("/connect/chatgpt") # guide user to connect first
raise Defensive patterns
Strategy: validation
Validate before calling
if codex_auth.load_oauth_bundle(provider_id) is None:
show_connect_prompt(provider_id) # avoid calling resolve_access entirely
# or via status helper:
if codex_auth.get_oauth_status(provider_id) != "connected":
show_connect_prompt(provider_id) Type guard
def provider_is_connected(provider_id: str) -> bool:
return codex_auth.load_oauth_bundle(provider_id) is not None Try / catch
try:
token, account = await codex_auth.resolve_access(provider_id)
except codex_auth.CodexAuthError as exc:
if "requires authorization" in str(exc):
return RedirectResponse("/connect/chatgpt")
raise Prevention
- Gate inference UI on connection status (get_oauth_status) before first call.
- Verify provider_id spelling matches the connect-time id.
- Point all workers at one installation DB.
- Treat 'requires authorization' as a connect prompt, never a retry loop.
When it happens
Trigger: Calling resolve_access for a provider whose OAuth bundle was never saved; after the user disconnected ChatGPT in Studio (bundle deleted); after a DB reset or migration dropped the oauth rows; wrong provider_id spelling; the same error is raised again inside the write-guard block if the bundle disappears between checks.
Common situations: Running inference before completing the ChatGPT connection; fresh installs; the disconnect path raced an in-flight request; multi-worker setups pointing at different installation DBs.
Related errors
- ChatGPT authorization is no longer valid. Please reconnect.
- ChatGPT authorization failed. Please reconnect.
- ChatGPT credential update is busy. Please retry.
- ChatGPT returned an invalid access token.
- The ChatGPT account identifier was missing.
AI-assisted analysis of unslothai/unsloth@203007d190 (2026-08-15).
Data as JSON: /api/errors/a239c9d55b1c8b18.
Report an issue: GitHub.