xtekky/gpt4free · error · MissingAuthError

Claude organization ID not found. Please set the 'CLAUDE_ORG

Error message

Claude organization ID not found. Please set the 'CLAUDE_ORGANIZATION_ID' environment variable.

What it means

MissingAuthError from g4f/Provider/needs_auth/Claude.py: after the cookie is resolved, the provider also needs an organization ID to build the API URL (base_url/{organization_id}). It is resolved once from CLAUDE_ORGANIZATION_ID env var, then from the lastActiveOrg cookie; if cls.organization_id stays unset the provider cannot construct a valid endpoint and raises.

Source

Thrown at g4f/Provider/needs_auth/Claude.py:44

        api_key: str = None,
        cookies: list = None,
        base_url: str = base_url,
        **kwargs,
    ) -> AsyncResult:
        api_key = os.environ.get("CLAUDE_COOKIE", api_key)
        cookies = cookies or get_cookies(cls.cookie_domain)
        if not api_key:
            api_key = "; ".join([f"{key}={value}" for key, value in cookies.items()])
        if not api_key:
            raise MissingAuthError(
                "Claude cookie not found. Please set the 'CLAUDE_COOKIE' environment variable."
            )
        if not cls.organization_id:
            cls.organization_id = os.environ.get("CLAUDE_ORGANIZATION_ID")
            if not cls.organization_id:
                cls.organization_id = cookies.get("lastActiveOrg")
            if not cls.organization_id:
                raise MissingAuthError(
                    "Claude organization ID not found. Please set the 'CLAUDE_ORGANIZATION_ID' environment variable."
                )
        async for chunk in super().create_async_generator(
            model=model,
            messages=messages,
            base_url=f"{base_url}/{cls.organization_id}",
            headers={"cookie": api_key},
            **kwargs,
        ):
            yield chunk

View on GitHub (pinned to 973504e177)

Solutions

  1. Set CLAUDE_ORGANIZATION_ID to your Claude organization UUID (visible in the claude.ai URL or settings when you switch organizations).
  2. Or include the lastActiveOrg cookie in your cookie string/jar: CLAUDE_COOKIE='sessionKey=...; lastActiveOrg=<org-uuid>'.
  3. Log in to claude.ai in the browser, open DevTools, and copy the full cookie header including lastActiveOrg.

Example fix

# before
os.environ["CLAUDE_COOKIE"] = "sessionKey=abc"
# MissingAuthError: organization ID not found

# after
os.environ["CLAUDE_COOKIE"] = "sessionKey=abc; lastActiveOrg=<org-uuid>"
# or: os.environ["CLAUDE_ORGANIZATION_ID"] = "<org-uuid>"
Defensive patterns

Strategy: validation

Validate before calling

import os

def claude_org_configured(cookie_value=None):
    if os.environ.get("CLAUDE_ORGANIZATION_ID"):
        return True
    return bool(cookie_value and "lastActiveOrg=" in cookie_value)

Try / catch

try:
    resp = await client.chat.completions.create(model=m, provider=Claude, messages=msgs)
except MissingAuthError as e:
    if "organization ID" in str(e):
        raise RuntimeError("Set CLAUDE_ORGANIZATION_ID or add lastActiveOrg cookie") from e

Prevention

When it happens

Trigger: Authenticating Claude with a raw cookie header (CLAUDE_COOKIE / api_key) that does not include the lastActiveOrg cookie, while CLAUDE_ORGANIZATION_ID is not set. Because api_key came from a string rather than the cookie jar, cookies.get("lastActiveOrg") has nothing to read.

Common situations: User copies only the sessionKey cookie into CLAUDE_COOKIE instead of the full header; organization cookie expired or not yet set (fresh account that never switched orgs); env var unset in deployment.

Related errors


AI-assisted analysis of xtekky/gpt4free@973504e177 (2026-08-14). Data as JSON: /api/errors/83a126bb05c230e4. Report an issue: GitHub.