{"record":{"id":"ed7531cd70590b7b","repo":"Hmbown/CodeWhale","slug":"deepseek-res-status-text-ed7531","errorCode":null,"errorMessage":"DeepSeek ${res.status}: ${text}","messagePattern":"DeepSeek (.+?): (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/lib/deepseek.ts","lineNumber":45,"sourceCode":"  const model = dsEnv?.model ?? process.env.DEEPSEEK_MODEL ?? FALLBACK_MODEL;\n  const res = await fetch(`${base}/v1/chat/completions`, {\n    method: \"POST\",\n    headers: {\n      \"Content-Type\": \"application/json\",\n      Authorization: `Bearer ${apiKey}`,\n    },\n    body: JSON.stringify({\n      model,\n      messages,\n      temperature: 0.4,\n      max_tokens: 4096,\n      reasoning_effort: \"high\",\n      ...(jsonMode ? { response_format: { type: \"json_object\" } } : {}),\n    }),\n  });\n  if (!res.ok) {\n    const text = await res.text();\n    throw new Error(`DeepSeek ${res.status}: ${text}`);\n  }\n  const data = (await res.json()) as ChatResponse;\n  return data.choices[0]?.message?.content ?? \"\";\n}\n\nconst SYSTEM_PROMPT = `You are the editor of \"今日要闻 / Today's Dispatch\", a daily-ish digest for the Codewhale open source project.\n\nYou receive: repo stats and a list of recently updated issues, PRs, and releases.\nOutput a single JSON object — no prose around it — matching this exact shape:\n\n{\n  \"headline\": \"string — English editorial headline (max ~70 chars)\",\n  \"summary\": \"string — 2-3 English sentences, calm factual editorial voice\",\n  \"highlights\": [\n    { \"title\": \"string\", \"href\": \"string\", \"tag\": \"shipped|merged|opened|discussion|release\", \"blurb\": \"one sentence, max ~120 chars\" }\n  ],\n  \"movers\": [\n    { \"number\": 123, \"title\": \"string\", \"href\": \"string\", \"reason\": \"one short clause\" }","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/Hmbown/CodeWhale/blob/8880682c63083a91624de936797efa3ce9e498fd/web/lib/deepseek.ts#L27-L63","documentation":"web/lib/deepseek.ts drives the 'Today's Dispatch' digest editor; when the DeepSeek chat API answers non-2xx it throws `DeepSeek <status>: <body text>` so Workers logs carry the upstream error verbatim (temperature 0.4, max_tokens 4096, optional json_object mode).","triggerScenarios":"generateDispatch calls with a missing/invalid DEEPSEEK_API_KEY (401), exhausted credits (402), rate limiting (429), an unknown model id (400), or DeepSeek 5xx during digest generation.","commonSituations":"Secret not set on the deployed Workers environment; expired key; the digest cron firing repeatedly into 429; the configured model drifting from DeepSeek's catalog.","solutions":["Set/rotate DEEPSEEK_API_KEY (wrangler secret put DEEPSEEK_API_KEY) and redeploy","Check the DeepSeek console balance for 402","Wrap the digest call in exponential backoff for 429/5xx","Confirm the model env value exists on api.deepseek.com"],"exampleFix":"// before\nif (!res.ok) {\n  const text = await res.text();\n  throw new Error(`DeepSeek ${res.status}: ${text}`);\n}\n\n// after - classify and retry transient failures\nif (res.status === 429 || res.status >= 500) {\n  await sleep(1000 * 2 ** attempt);\n  continue;\n}\nif (!res.ok) {\n  const text = await res.text();\n  throw new Error(`DeepSeek ${res.status}: ${text}`);\n}","handlingStrategy":"retry","validationCode":"const apiKey = (env.DEEPSEEK_API_KEY || '').trim();\nif (!apiKey) {\n  return new Response('dispatch generator is not configured (missing DEEPSEEK_API_KEY)', { status: 503 });\n}","typeGuard":null,"tryCatchPattern":"catch (err) {\n  const m = /^DeepSeek (\\d+):/.exec(String(err.message));\n  if (m && (m[1] === '429' || Number(m[1]) >= 500)) {\n    ctx.waitUntil(scheduleRetryIn(60)); // back off and retry the digest later\n    return;\n  }\n  console.error('dispatch generation failed:', err.message);\n}","preventionTips":["Set secrets via wrangler and verify with wrangler secret list before relying on the cron","Retry digests idempotently - regeneration should be safe to repeat","Alert on repeated 401/402 so key/balance issues surface quickly"],"tags":["deepseek","api","llm","cloudflare-workers"],"backgroundTag":null,"analyzedSha":"8880682c63083a91624de936797efa3ce9e498fd","analyzedAt":"2026-08-16T11:31:27.956Z","schemaVersion":2},"datasetVersion":"2026-08-16T13:17:31.715Z"}