{"record":{"id":"8c92bdde785b6536","repo":"nikivdev/code","slug":"device-auth-start-failed-http","errorCode":null,"errorMessage":"device auth start failed: HTTP {}","messagePattern":"device auth start failed: HTTP (.+?)","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/auth.rs","lineNumber":54,"sourceCode":"    let api_url = api_url_override\n        .or_else(|| env::load_ai_api_url().ok())\n        .unwrap_or_else(|| \"https://myflow.sh\".to_string());\n    let api_url = api_url.trim().trim_end_matches('/').to_string();\n\n    let client = Client::builder()\n        .timeout(Duration::from_secs(30))\n        .build()\n        .context(\"failed to create HTTP client for auth\")?;\n\n    let start_url = format!(\"{}/api/auth/cli/start\", api_url);\n    let response = client\n        .post(&start_url)\n        .json(&serde_json::json!({\"client\": \"flow\"}))\n        .send()\n        .context(\"failed to start device auth\")?;\n\n    if !response.status().is_success() {\n        bail!(\"device auth start failed: HTTP {}\", response.status());\n    }\n\n    let payload: DeviceStartResponse = response\n        .json()\n        .context(\"failed to parse device auth response\")?;\n\n    println!(\"\\nFlow auth with myflow\");\n    println!(\"───────────────────────\");\n    println!(\"Code: {}\", payload.user_code);\n    println!(\"Open: {}\\n\", payload.verification_url);\n\n    open_in_browser(&payload.verification_url);\n\n    let expires_at = Instant::now() + Duration::from_secs(payload.expires_in);\n    let poll_url = format!(\"{}/api/auth/cli/poll\", api_url);\n\n    println!(\"Waiting for approval...\");\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/nikivdev/code/blob/a747e741ae92c09071d0ae946ab48488adcff1ce/src/auth.rs#L36-L72","documentation":"The device-code login flow (login in auth.rs) first POSTs {\"client\":\"flow\"} to the device-auth start endpoint. Any non-2xx response aborts with this error, embedding the HTTP status. This happens before any polling or token exchange, so it indicates the auth server refused to initiate the flow.","triggerScenarios":"POST to start_url returns 4xx/5xx: auth server down, client blocked, wrong API base URL configured, rate limited, or endpoint path changed server-side.","commonSituations":"Misconfigured API URL (pointing at the wrong environment); corporate proxy blocking the request; auth service outage; the 'flow' client id being rejected after an API rename.","solutions":["Check the HTTP status in the message (404 → wrong URL/path, 401/403 → client blocked, 429 → rate limited, 5xx → server side)","Verify the configured API base URL is correct for your environment (env var / config)","Retry later if it's a 5xx/429 (server outage or rate limit)","Inspect the response body via a manual curl of the start endpoint to see the server's error detail"],"exampleFix":"// before\nif !response.status().is_success() {\n    bail!(\"device auth start failed: HTTP {}\", response.status());\n}\n// after\nlet status = response.status();\nlet body = response.text().unwrap_or_default();\nbail!(\"device auth start failed: HTTP {} (body: {})\", status, body);","handlingStrategy":"retry","validationCode":"fn api_base_url_configured() -> Result<(), String> {\n    match std::env::var(\"FLOW_API_URL\") {\n        Ok(url) if url.starts_with(\"http\") => Ok(()),\n        Ok(url) => Err(format!(\"FLOW_API_URL is not a valid http(s) URL: {}\", url)),\n        Err(_) => Err(\"FLOW_API_URL not set\".to_string()),\n    }\n}","typeGuard":null,"tryCatchPattern":"match login(&api_url) {\n    Err(e) if e.to_string().contains(\"device auth start failed\") => {\n        eprintln!(\"{}\\nCheck your API URL and network, then try again.\", e);\n    }\n    other => other?,\n}","preventionTips":["Verify the API base URL/environment before login","Handle 429/5xx with retry + backoff instead of immediate bail","Log the response body for server-side error detail","Check proxy/VPN interference if failures are environment-specific"],"tags":["network","http","authentication","device-auth"],"backgroundTag":"device-auth-flow-failed","analyzedSha":"a747e741ae92c09071d0ae946ab48488adcff1ce","analyzedAt":"2026-09-01T22:43:55.719Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}