xtekky/gpt4free · error · MissingAuthError

Add a "api_key"

Error message

Add a "api_key"

What it means

Error "Add a "api_key"" thrown in xtekky/gpt4free.

Source

Thrown at g4f/Provider/template/OpenaiTemplate.py:226

            "logit_bias",
            "modalities",
            "audio",
            "stream_options",
            "include_reasoning",
            "response_format",
            "max_completion_tokens",
            "reasoning_effort",
            "search_settings",
            "prompt_cache_key",
        ],
        extra_body: dict = None,
        yield_request: bool = True,
        **kwargs,
    ) -> AsyncResult:
        if api_key is None and cls.api_key is not None:
            api_key = cls.api_key
        if cls.needs_auth and api_key is None:
            raise MissingAuthError('Add a "api_key"')
        async with StreamSession(
            proxy=proxy,
            headers=cls.get_headers(stream, api_key, headers),
            timeout=timeout,
            impersonate=impersonate,
        ) as session:
            model = cls.get_model(model, api_key=api_key, base_url=base_url)
            if base_url is None:
                base_url = (
                    cls.base_url if cls.is_provider_api_key(api_key) else cls.backup_url
                )

            # Proxy for image generation feature
            if model and model in cls.image_models or prompt:
                prompt = format_media_prompt(messages, prompt)
                size = use_aspect_ratio(
                    {"width": kwargs.get("width"), "height": kwargs.get("height")},
                    kwargs.get("aspect_ratio", None),

View on GitHub (pinned to 973504e177)

Solutions

  1. Pass an api_key argument to the provider call.
  2. Set the provider's API key environment variable before calling.

When it happens

Trigger: Thrown at g4f/Provider/template/OpenaiTemplate.py:226 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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