{"record":{"id":"f61c09bd50dd6f45","repo":"xtekky/gpt4free","slug":"api-key-is-required-for-puter-js-api","errorCode":null,"errorMessage":"API key is required for Puter.js API","messagePattern":"API key is required for Puter\\.js API","errorType":"exception","errorClass":"MissingAuthError","httpStatus":null,"severity":"error","filePath":"g4f/Provider/needs_auth/Puter.py","lineNumber":415,"sourceCode":"            \"temperature\",\n            \"presence_penalty\",\n            \"top_p\",\n            \"frequency_penalty\",\n            \"response_format\",\n            \"tools\",\n            \"parallel_tool_calls\",\n            \"tool_choice\",\n            \"reasoning_effort\",\n            \"logit_bias\",\n            \"voice\",\n            \"modalities\",\n            \"audio\",\n            \"prompt_cache_key\",\n        ],\n        **kwargs,\n    ) -> AsyncResult:\n        if not api_key:\n            raise MissingAuthError(\"API key is required for Puter.js API\")\n\n        # Check if we need to use a vision model\n        if not model and media is not None and len(media) > 0:\n            model = cls.default_vision_model\n\n        # Check for image URLs in messages\n        if not model:\n            for msg in messages:\n                if msg[\"role\"] == \"user\":\n                    content = msg.get(\"content\", \"\")\n                    if isinstance(content, list):\n                        for item in content:\n                            if item.get(\"type\") == \"image_url\":\n                                model = cls.default_vision_model\n                                break\n\n        # Get the model name from the user-provided model\n        try:","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/xtekky/gpt4free/blob/973504e1770928ed5fb82f43da528f441ad9ddc3/g4f/Provider/needs_auth/Puter.py#L397-L433","documentation":"Raised as MissingAuthError by the Puter provider when create_async_generator is invoked without an api_key. Puter.js requires an explicit key; unlike cookie-based providers it has no HAR/browser fallback, so the call aborts before any request is made.","triggerScenarios":"Calling the Puter provider (model routed to Puter, or provider=g4f.Provider.Puter) without passing api_key in kwargs, with no api_key stored in the client/provider config.","commonSituations":"Switching an existing g4f integration to Puter without adding credentials, assuming g4f auto-authenticates all providers, running examples copied from docs that omit the key.","solutions":["Pass api_key when creating the completion: client.chat.completions.create(..., api_key='...')","Set the key in the provider/client configuration so all calls pick it up","Obtain a Puter.js API key from the Puter dashboard first if you do not have one"],"exampleFix":"# before\nresponse = client.chat.completions.create(model='gpt-4o', messages=msgs)  # MissingAuthError\n\n# after\nresponse = client.chat.completions.create(model='gpt-4o', messages=msgs, api_key=os.environ['PUTER_API_KEY'])","handlingStrategy":"validation","validationCode":"api_key = os.environ.get('PUTER_API_KEY')\nif not api_key:\n    raise SystemExit('Set PUTER_API_KEY before calling the Puter provider')","typeGuard":"def can_call_puter(api_key: str | None) -> bool:\n    return isinstance(api_key, str) and api_key.strip() != ''","tryCatchPattern":"from g4f.errors import MissingAuthError\ntry:\n    ...create(...)\nexcept MissingAuthError as e:\n    logging.error('Credentials missing: %s', e)","preventionTips":["Load provider credentials from env at app startup and fail fast if absent","Maintain a per-provider credential map so routing never reaches Puter keyless"],"tags":["authentication","missing-api-key","puter","g4f"],"backgroundTag":null,"analyzedSha":"973504e1770928ed5fb82f43da528f441ad9ddc3","analyzedAt":"2026-08-14T23:45:32.408Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}