{"record":{"id":"92ca64539da91854","repo":"Hmbown/CodeWhale","slug":"xai-oauth-credentials-not-found-options-1-run","errorCode":null,"errorMessage":"xAI OAuth credentials not found.\nOptions:\n1. Run `codewhale auth xai-device` for Codewhale-owned OAuth storage\n2. To read an existing Grok CLI login without changing it, run `codewhale auth external-consent --provider xai --mode read-only --path {}`\n3. Or use API-key auth: export XAI_API_KEY=... / codewhale auth set --provider xai","messagePattern":"xAI OAuth credentials not found\\.\nOptions:\n1\\. Run `codewhale auth xai-device` for Codewhale-owned OAuth storage\n2\\. To read an existing Grok CLI login without changing it, run `codewhale auth external-consent --provider xai --mode read-only --path (.+?)`\n3\\. Or use API-key auth: export XAI_API_KEY=\\.\\.\\. / codewhale auth set --provider xai","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/tui/src/config.rs","lineNumber":6724,"sourceCode":"                    provider_config_table_name(provider)?\n                );\n            }\n            ApiProvider::Anthropic | ApiProvider::Openmodel => {\n                anyhow::bail!(\"{}\", missing_provider_api_key_message(provider)?)\n            }\n            ApiProvider::OpencodeZen => {\n                anyhow::bail!(\"{}\", missing_provider_api_key_message(provider)?)\n            }\n            ApiProvider::OpenaiCodex => anyhow::bail!(\"{}\", crate::oauth::missing_auth_message()),\n            ApiProvider::Xai => {\n                // Prefer OAuth guidance when auth_mode requests it or Grok CLI\n                // tokens already exist; otherwise show both API-key and OAuth.\n                if self\n                    .provider_config_for(provider)\n                    .is_some_and(provider_config_uses_xai_oauth)\n                    || crate::xai_oauth::credentials_present(self)\n                {\n                    anyhow::bail!(\"{}\", crate::xai_oauth::missing_auth_message());\n                }\n                anyhow::bail!(\n                    \"xAI API key not found. Get a key: https://console.x.ai/\\n\\\n                     Run 'codewhale auth set --provider xai', set XAI_API_KEY, or add \\\n                     [providers.xai] api_key.\\n\\\n                     OAuth alternative: run `codewhale auth xai-device` for \\\n                     Codewhale-owned storage and set [providers.xai] auth_mode = \\\"oauth\\\".\"\n                );\n            }\n            // Self-hosted deployments commonly run without auth on localhost.\n            // Return an empty key and let the client omit the Authorization header.\n            ApiProvider::Sglang | ApiProvider::Vllm => Ok(String::new()),\n            ApiProvider::Ollama\n                if provider_route_is_keyless_self_hosted(provider, &self.deepseek_base_url()) =>\n            {\n                Ok(String::new())\n            }\n            ApiProvider::Ollama => {","sourceCodeStart":6706,"sourceCodeEnd":6742,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/0c42157ee52f9d55af2b506d71b46249910f77d3/crates/tui/src/config.rs#L6706-L6742","documentation":"When the xAI route is in OAuth mode - either [providers.xai] auth_mode = \"oauth\" or Grok CLI tokens already exist on disk - and no OAuth credential is usable, the Xai arm bails with xai_oauth::missing_auth_message() (crates/tui/src/xai_oauth.rs:776). The message offers the three supported paths: Codewhale-owned device OAuth, read-only import of an existing Grok CLI login, or plain API-key auth.","triggerScenarios":"provider == ApiProvider::Xai with provider_config_uses_xai_oauth true or xai_oauth::credentials_present(self) true, and the owned OAuth store plus consent grants yield nothing. The first bail inside the Xai arm fires with the xai_oauth message.","commonSituations":"Setting auth_mode = \"oauth\" but never completing 'codewhale auth xai-device'; a partial Grok CLI login file; switching machines and losing the owned OAuth storage while the config still says oauth.","solutions":["Run 'codewhale auth xai-device' to complete device-login into Codewhale-owned OAuth storage","To reuse an existing Grok CLI login read-only: codewhale auth external-consent --provider xai --mode read-only --path <grok-auth-file>","Or drop OAuth: remove auth_mode = \"oauth\" from [providers.xai] and use export XAI_API_KEY=... / codewhale auth set --provider xai"],"exampleFix":"# before\n[providers.xai]\nauth_mode = \"oauth\"\n\n# after\n$ codewhale auth xai-device   # completes device login\n[providers.xai]\nauth_mode = \"oauth\"","handlingStrategy":"try-catch","validationCode":"if provider == ApiProvider::Xai\n    && route.auth_mode.as_deref() == Some(\"oauth\")\n    && !xai_owned_token_present()\n    && !xai_read_only_grant_present()\n{\n    eprintln!(\"complete 'codewhale auth xai-device' or grant read-only consent before launch\");\n}","typeGuard":"fn xai_oauth_ready(auth_mode_oauth: bool, owned: bool, grant: bool) -> bool {\n    !auth_mode_oauth || owned || grant\n}","tryCatchPattern":"match config.deepseek_api_key() {\n    Err(e) if e.to_string().starts_with(\"xAI OAuth credentials not found\") => {\n        // offer the three options verbatim: xai-device, external-consent read-only, or API key\n    }\n    other => other?,\n}","preventionTips":["Finish 'codewhale auth xai-device' before setting auth_mode = \"oauth\" in [providers.xai]","Existing Grok CLI logins only work through an explicit read-only consent grant with --path","If you do not want OAuth, remove auth_mode = \"oauth\" so the plain API-key path applies"],"tags":["oauth","xai","grok","credentials","device-login"],"backgroundTag":"missing-oauth-token","analyzedSha":"0c42157ee52f9d55af2b506d71b46249910f77d3","analyzedAt":"2026-08-20T21:50:45.477Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}