{"record":{"id":"cef88a1652a2224f","repo":"warpdotdev/warp","slug":"your-api-key-is-invalid-please-provide-a-valid-ke","errorCode":null,"errorMessage":"Your API key is invalid. Please provide a valid key via '--api-key' or the WARP_API_KEY environment variable.","messagePattern":"Your API key is invalid\\. Please provide a valid key via '--api-key' or the WARP_API_KEY environment variable\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/src/ai/agent_sdk/mod.rs","lineNumber":1709,"sourceCode":"        if dispatched {\n            return;\n        }\n        match event {\n            AuthManagerEvent::AuthComplete => {\n                dispatched = true;\n                if let Err(err) = dispatch_command(ctx, command.clone(), global_options.clone()) {\n                    report_fatal_error(err, ctx);\n                }\n            }\n            AuthManagerEvent::NeedsReauth => {\n                dispatched = true;\n                let auth_state = AuthStateProvider::handle(ctx).as_ref(ctx).get();\n                let message = if auth_state.is_api_key_authenticated() {\n                    \"Your API key is invalid. Please provide a valid key via '--api-key' or the WARP_API_KEY environment variable.\".to_string()\n                } else {\n                    format!(\"Your credentials are invalid. Please log in again with `{cli_name} login`.\")\n                };\n                report_fatal_error(anyhow::anyhow!(message), ctx);\n            }\n            AuthManagerEvent::AuthFailed(err) => {\n                dispatched = true;\n                report_fatal_error(anyhow::anyhow!(\"Authentication failed: {err:#}\"), ctx);\n            }\n            _ => {}\n        }\n    });\n\n    // Trigger authentication - the subscription above will handle the result.\n    AuthManager::handle(ctx).update(ctx, |auth_manager, ctx| match authentication {\n        CommandAuthentication::PendingApiKey(api_key) => {\n            auth_manager.authenticate_api_key(api_key, ctx);\n        }\n        CommandAuthentication::RefreshUser => auth_manager.refresh_user(ctx),\n    });\n}\n","sourceCodeStart":1691,"sourceCodeEnd":1727,"githubUrl":"https://github.com/warpdotdev/warp/blob/e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc/app/src/ai/agent_sdk/mod.rs#L1691-L1727","documentation":"While authenticating with an explicit API key, the AuthManager emitted NeedsReauth and the auth state shows API-key authentication — the server rejected the key (invalid, revoked, or from the wrong environment). This branch is specifically chosen when `auth_state.is_api_key_authenticated()` is true.","triggerScenarios":"Running any auth-required command with WARP_API_KEY or --api-key set to a key the server rejects: revoked or deleted key, typo/truncation, a staging key used against production (or vice versa), or shell quoting artifacts in the variable.","commonSituations":"Rotated/revoked keys left in CI secrets; copy-paste whitespace or quotes in WARP_API_KEY; environment mismatch between the key's origin and the targeted SERVER_ROOT_URL.","solutions":["Generate a fresh API key and update WARP_API_KEY / the --api-key value","Check the variable for stray quotes or whitespace (inspect its length, keep the value out of logs)","Confirm the key belongs to the same environment the CLI targets (staging vs production)","Fall back to interactive `warp login` if API-key management is not required"],"exampleFix":"# before\nexport WARP_API_KEY=\"pk_old_revoked_key\"\n\n# after\nexport WARP_API_KEY=pk_freshly_generated_key   # no quotes needed; avoids stray characters","handlingStrategy":"try-catch","validationCode":"# Cheap sanity checks on the key variable without printing its value\n[ -n \"$WARP_API_KEY\" ] || { echo 'WARP_API_KEY empty' >&2; exit 1; }\n[ \"${#WARP_API_KEY}\" -ge 20 ] || { echo 'WARP_API_KEY suspiciously short' >&2; exit 1; }","typeGuard":null,"tryCatchPattern":"out=$(warp agent list 2>&1) || { case \"$out\" in\n  *'API key is invalid'*) WARP_API_KEY=$(fetch_fresh_key) && warp agent list ;;\n  *) echo \"$out\" >&2; exit 1 ;;\nesac; }","preventionTips":["Rotate keys before expiry and update CI secrets atomically","Never wrap the key variable in quotes that can leak into the value","Match keys to environments: separate staging and production keys"],"tags":["authentication","api-key","credentials"],"backgroundTag":null,"analyzedSha":"e72fd7aacbbb2236d9b3be2aad7e7178fe94b4bc","analyzedAt":"2026-08-16T08:27:25.381Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}