{"record":{"id":"fb8f90a8e4763ba7","repo":"can1357/oh-my-pi","slug":"kimi-search-api-error-response-status-erro","errorCode":null,"errorMessage":"Kimi search API error (${response.status}): ${errorText}","messagePattern":"Kimi search API error \\((.+?)\\): (.+?)","errorType":"exception","errorClass":"SearchProviderError","httpStatus":null,"severity":"error","filePath":"packages/coding-agent/src/web/search/providers/kimi.ts","lineNumber":134,"sourceCode":"\t\theaders: {\n\t\t\tAccept: \"application/json\",\n\t\t\t\"Content-Type\": \"application/json\",\n\t\t\tAuthorization: `Bearer ${apiKey}`,\n\t\t},\n\t\tbody: JSON.stringify({\n\t\t\ttext_query: params.query,\n\t\t\tlimit: params.limit,\n\t\t\tenable_page_crawling: params.includeContent,\n\t\t\ttimeout_seconds: DEFAULT_TIMEOUT_SECONDS,\n\t\t}),\n\t\tsignal: withHardTimeout(params.signal, params.timeoutMs),\n\t});\n\n\tif (!response.ok) {\n\t\tconst errorText = await response.text();\n\t\tconst classified = classifyProviderHttpError(\"kimi\", response.status, errorText);\n\t\tif (classified) throw classified;\n\t\tthrow new SearchProviderError(\n\t\t\t\"kimi\",\n\t\t\t`Kimi search API error (${response.status}): ${errorText}`,\n\t\t\tresponse.status,\n\t\t);\n\t}\n\n\tconst data = (await response.json()) as KimiSearchResponse;\n\tconst requestId = response.headers.get(\"x-request-id\") ?? response.headers.get(\"x-msh-request-id\") ?? undefined;\n\treturn { response: data, requestId };\n}\n\n/** Execute Kimi web search. */\nexport async function searchKimi(params: KimiSearchParams): Promise<SearchResponse> {\n\tconst keyOrResolver = await resolveKey(params.authStorage, params.sessionId, params.signal);\n\tif (!keyOrResolver) {\n\t\tthrow new Error(\n\t\t\t\"Kimi search credentials not found. Kimi web search uses the Kimi Code service (api.kimi.com); set MOONSHOT_SEARCH_API_KEY / KIMI_SEARCH_API_KEY to a Kimi Code Console key, or login with 'omp /login kimi-code'. A Moonshot Open Platform key (MOONSHOT_API_KEY) is not accepted here.\",\n\t\t);","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/can1357/oh-my-pi/blob/969062200754ea02cfac922e5ebb8c608c079e15/packages/coding-agent/src/web/search/providers/kimi.ts#L116-L152","documentation":"Thrown by callKimiSearch when the Kimi search API responds with a non-OK HTTP status that classifyProviderHttpError does not classify. The error message embeds both the HTTP status and the raw response body text for diagnosis, with the status attached to the SearchProviderError.","triggerScenarios":"Any searchKimi call where the Kimi (api.kimi.com) endpoint returns status outside the classified set — e.g. 402, 409, 502/504 variants — with the body captured in errorText.","commonSituations":"Kimi service incidents returning 5xx with HTML error pages; rate-limit variants not covered by classification; transient gateway errors between client and Kimi.","solutions":["Inspect errorText in the message — it contains Kimi's own error description","Retry with backoff for 5xx statuses; treat 4xx as non-retryable","Verify the API key and endpoint (Kimi Code console key, not Moonshot platform key)","Check Kimi service status for outages"],"exampleFix":"// before\nconst results = await searchKimi({ query, authStorage });\n// after\ntry {\n  const results = await searchKimi({ query, authStorage });\n} catch (err) {\n  if (err instanceof SearchProviderError && (err.status ?? 500) >= 500) {\n    await Bun.sleep(retryDelay); // retry transient 5xx\n  }\n}","handlingStrategy":"retry","validationCode":"// preflight credential check against Kimi Code service\nif (!process.env.MOONSHOT_SEARCH_API_KEY && !process.env.KIMI_SEARCH_API_KEY) {\n  throw new Error('Kimi search key missing');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const res = await searchKimi({ query, authStorage });\n} catch (err) {\n  if (err instanceof SearchProviderError && (err.status ?? 0) >= 500) {\n    await Bun.sleep(1000); return searchKimi({ query, authStorage }); // bounded retry\n  }\n  throw err;\n}","preventionTips":["Use a Kimi Code Console key, not a Moonshot platform key","Retry only transient 5xx with capped backoff","Monitor Kimi service status for incidents","Capture errorText from messages when filing issues"],"tags":["api","http","kimi","error-response"],"backgroundTag":"api-error-response-code","analyzedSha":"969062200754ea02cfac922e5ebb8c608c079e15","analyzedAt":"2026-08-31T10:29:35.737Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}