appwrite/appwrite · error · Exception

Failed to create API key

Error message

Failed to create API key

What it means

Error "Failed to create API key" thrown in appwrite/appwrite.

Source

Thrown at src/Appwrite/Platform/Tasks/Screenshot.php:195

        }

        Console::info("Site created");

        $siteId = $site['body']['$id'];

        // Prepare API key, incase it's needed as variable
        $response = $client->call(Client::METHOD_POST, '/projects/' . $projectId . '/keys', [
            'content-type' => 'application/json',
            'x-appwrite-project' => 'console',
            'cookie' => $cookieConsole
        ], [
            'name' => 'Screenshot API key',
            'scopes' => \array_keys(Config::getParam('projectScopes', []))
        ]);

        if ($response['headers']['status-code'] !== 201) {
            Console::error(\json_encode($response));
            throw new \Exception("Failed to create API key");
        }

        $apiKey = $response['body']['secret'];

        Console::info("API key created");

        $variables['APPWRITE_API_KEY'] = $apiKey;

        // Create variables
        if (!empty($template['variables'] ?? [])) {
            foreach ($template['variables'] as $variable) {
                $name = $variable['name'];

                $value = $variable['value'];
                $value = \str_replace('{projectName}', $projectName, $value);
                $value = \str_replace('{projectId}', $projectId, $value);
                $value = \str_replace('{apiEndpoint}', 'http://' . System::getEnv('_APP_DOMAIN', '') . '/v1', $value);

View on GitHub (pinned to a1d520eea4)

Solutions

  1. Check the logged API response for the exact error (e.g., invalid scopes).
  2. Verify the 'projectScopes' config contains valid scope names for this Appwrite version.
  3. Confirm the project was created successfully and the console session cookie is still valid.

When it happens

Trigger: Thrown at src/Appwrite/Platform/Tasks/Screenshot.php:195 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of appwrite/appwrite@a1d520eea4 (2026-08-18). Data as JSON: /api/errors/e9435f9e3804df6c. Report an issue: GitHub.