{"record":{"id":"0303a87341047ff2","repo":"xtekky/gpt4free","slug":"missing-api-key","errorCode":null,"errorMessage":"Missing \"api_key\"","messagePattern":"Missing \"api_key\"","errorType":"validation","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/GigaChat.py","lineNumber":96,"sourceCode":"    ]\n\n    @classmethod\n    async def create_async_generator(\n        cls,\n        model: str,\n        messages: Messages,\n        stream: bool = True,\n        proxy: str = None,\n        api_key: str = None,\n        connector: BaseConnector = None,\n        scope: str = \"GIGACHAT_API_PERS\",\n        update_interval: float = 0,\n        **kwargs,\n    ) -> AsyncResult:\n        global access_token, token_expires_at\n        model = cls.get_model(model)\n        if not api_key:\n            raise MissingAuthError('Missing \"api_key\"')\n\n        # Create certificate file in cookies directory\n        cookies_dir = Path(get_cookies_dir())\n        cert_file = cookies_dir / \"russian_trusted_root_ca.crt\"\n\n        # Write certificate if it doesn't exist\n        if not cert_file.exists():\n            cert_file.write_text(RUSSIAN_CA_CERT)\n\n        if has_ssl and connector is None:\n            ssl_context = ssl.create_default_context(cafile=str(cert_file))\n            connector = TCPConnector(ssl_context=ssl_context)\n\n        async with ClientSession(connector=get_connector(connector, proxy)) as session:\n            if token_expires_at - int(time.time() * 1000) < 60000:\n                async with session.post(\n                    url=\"https://ngw.devices.sberbank.ru:9443/api/v2/oauth\",\n                    headers={","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/GigaChat.py#L78-L114","documentation":"GigaChat.create_async_generator raises MissingAuthError when the api_key argument is falsy. The GigaChat API requires a client API key (base64 client credentials) that is exchanged for a short-lived access token with the selected scope (default GIGACHAT_API_PERS). Unlike some providers there is no anonymous fallback.","triggerScenarios":"Calling the GigaChat provider (directly or via the g4f client) without api_key in kwargs and without a configured default key in settings.","commonSituations":"Provider selected by name without credentials; API key configured in a different settings field or env var so g4f does not see it; key passed under the wrong kwarg name.","solutions":["Pass the key explicitly: await client.chat.completions.create(model='...', messages=..., provider=g4f.Provider.GigaChat, api_key='<GIGACHAT_KEY>')","Or add the key in g4f settings so it is injected automatically","Confirm you are using a GigaChat-issued client key and the right scope (GIGACHAT_API_PERS vs GIGACHAT_API_B2B or API_CORP) for your account"],"exampleFix":"// before\nresponse = await client.chat.completions.create(model='GigaChat', messages=messages, provider=g4f.Provider.GigaChat)\n\n// after\nresponse = await client.chat.completions.create(model='GigaChat', messages=messages, provider=g4f.Provider.GigaChat, api_key=os.environ['GIGACHAT_API_KEY'])","handlingStrategy":"validation","validationCode":"import os\n\napi_key = os.environ.get(\"GIGACHAT_API_KEY\")\nif not api_key:\n    raise ValueError(\"GigaChat requires an api_key; set GIGACHAT_API_KEY or configure it in g4f settings\")\nresponse = await client.chat.completions.create(\n    model=model, messages=messages, provider=g4f.Provider.GigaChat, api_key=api_key\n)","typeGuard":null,"tryCatchPattern":"from g4f.errors import MissingAuthError\ntry:\n    async for chunk in GigaChat.create_async_generator(model, messages):\n        ...\nexcept MissingAuthError as e:\n    if 'api_key' in str(e):\n        raise ConfigurationError(\"supply GigaChat api_key\") from e","preventionTips":["Check for the key before invoking the provider; fail fast with a clear config message","Store the key in settings or env, not hardcoded","Match the scope (PERS/B2B/CORP) to the account type the key was issued for"],"tags":["auth","gigachat","api-key","configuration","missing-credentials"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}