{"record":{"id":"8bdf661757bb1de7","repo":"xtekky/gpt4free","slug":"claude-cookie-not-found-please-set-the-claude-co","errorCode":null,"errorMessage":"Claude cookie not found. Please set the 'CLAUDE_COOKIE' environment variable.","messagePattern":"Claude cookie not found\\. Please set the 'CLAUDE_COOKIE' environment variable\\.","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Claude.py","lineNumber":36,"sourceCode":"    organization_id = None\n    cookie_domain = \"claude.ai\"\n\n    @classmethod\n    async def create_async_generator(\n        cls,\n        model: str,\n        messages: Messages,\n        api_key: str = None,\n        cookies: list = None,\n        base_url: str = base_url,\n        **kwargs,\n    ) -> AsyncResult:\n        api_key = os.environ.get(\"CLAUDE_COOKIE\", api_key)\n        cookies = cookies or get_cookies(cls.cookie_domain)\n        if not api_key:\n            api_key = \"; \".join([f\"{key}={value}\" for key, value in cookies.items()])\n        if not api_key:\n            raise MissingAuthError(\n                \"Claude cookie not found. Please set the 'CLAUDE_COOKIE' environment variable.\"\n            )\n        if not cls.organization_id:\n            cls.organization_id = os.environ.get(\"CLAUDE_ORGANIZATION_ID\")\n            if not cls.organization_id:\n                cls.organization_id = cookies.get(\"lastActiveOrg\")\n            if not cls.organization_id:\n                raise MissingAuthError(\n                    \"Claude organization ID not found. Please set the 'CLAUDE_ORGANIZATION_ID' environment variable.\"\n                )\n        async for chunk in super().create_async_generator(\n            model=model,\n            messages=messages,\n            base_url=f\"{base_url}/{cls.organization_id}\",\n            headers={\"cookie\": api_key},\n            **kwargs,\n        ):\n            yield chunk","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Claude.py#L18-L54","documentation":"MissingAuthError from g4f/Provider/needs_auth/Claude.py raised during create_async_generator: the provider needs a Claude (claude.ai) cookie string to authenticate, resolved from the CLAUDE_COOKIE env var, the caller-supplied api_key, or a cookie jar for the provider's cookie_domain. If none yields a value, the request cannot carry authentication, so it fails before any network call.","triggerScenarios":"Calling Claude via g4f with no CLAUDE_COOKIE environment variable, no api_key argument, and no exported claude.ai cookies in g4f's cookie storage. The code builds api_key from env, then falls back to joining jar cookies; if both are empty the error is raised.","commonSituations":"New machine/container without CLAUDE_COOKIE set; cookies exported but for the wrong domain so the jar is empty; CI environments that never had the var configured.","solutions":["Export the claude.ai cookie header from a logged-in browser session and set it: export CLAUDE_COOKIE='cookieKey=value; otherKey=value'.","Alternatively place a claude.ai HAR/cookies file in g4f's har_and_cookies directory so get_cookies(cls.cookie_domain) returns entries.","Alternatively pass api_key=\"<cookie header string>\" when calling the provider.","Verify the cookie domain in your export matches the provider's cls.cookie_domain."],"exampleFix":"# before\n# no env var, no cookies -> MissingAuthError\nresp = await client.chat.completions.create(model=\"claude-...\", provider=Claude, messages=msgs)\n\n# after\nimport os\nos.environ[\"CLAUDE_COOKIE\"] = \"sessionKey=...; otherKey=...\"\nresp = await client.chat.completions.create(model=\"claude-...\", provider=Claude, messages=msgs)","handlingStrategy":"validation","validationCode":"import os\n\ndef claude_cookie_configured():\n    return bool(os.environ.get(\"CLAUDE_COOKIE\"))","typeGuard":null,"tryCatchPattern":"try:\n    resp = await client.chat.completions.create(model=m, provider=Claude, messages=msgs)\nexcept MissingAuthError as e:\n    if \"CLAUDE_COOKIE\" in str(e):\n        os.environ[\"CLAUDE_COOKIE\"] = fetch_fresh_cookie_header()\n        resp = await client.chat.completions.create(model=m, provider=Claude, messages=msgs)","preventionTips":["Set CLAUDE_COOKIE at deploy time and fail fast if unset.","Copy the entire cookie header string, not a single cookie.","Refresh the cookie when Claude starts returning auth errors mid-session."],"tags":["authentication","cookies","environment-variable","claude"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}