{"record":{"id":"a3be5cf78d8091e8","repo":"nexu-io/open-design","slug":"tag-resp-status-truncate-text-240","errorCode":null,"errorMessage":"${tag} ${resp.status}: ${truncate(text, 240)}","messagePattern":"\\$\\{tag\\} \\$\\{resp\\.status\\}: \\$\\{truncate\\(text, 240\\)\\}","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":953,"sourceCode":"    // Azure's canonical auth header. Some deployments accept Bearer\n    // (the curl example we tested against does) but api-key is what\n    // their docs document, so send both. OpenAI ignores unknown\n    // headers, so this is harmless on the standard endpoint too.\n    headers['api-key'] = credentials.apiKey;\n  }\n\n  const resp = await fetch(url, withMediaRequestInit(ctx, {\n    method: 'POST',\n    headers,\n    body: JSON.stringify(body),\n    dispatcher: ctx.requestInit.dispatcher\n      ?? openAIImageDispatcher as unknown as NonNullable<RequestInit['dispatcher']>,\n    signal: AbortSignal.timeout(Math.max(OPENAI_IMAGE_HEADERS_TIMEOUT_MS, OPENAI_IMAGE_BODY_TIMEOUT_MS)),\n  }));\n  const text = await resp.text();\n  if (!resp.ok) {\n    const tag = azure ? 'azure-openai' : 'openai';\n    throw new Error(`${tag} ${resp.status}: ${truncate(text, 240)}`);\n  }\n  let data: any;\n  try {\n    data = JSON.parse(text);\n  } catch {\n    throw new Error(`openai non-JSON response: ${truncate(text, 200)}`);\n  }\n  const entry = data && Array.isArray(data.data) ? data.data[0] : null;\n  if (!entry) throw new Error('openai response had no data[0]');\n  let bytes;\n  if (entry.b64_json) {\n    bytes = Buffer.from(entry.b64_json, 'base64');\n  } else if (entry.url) {\n    const imgResp = await fetch(entry.url, withMediaRequestInit(ctx));\n    if (!imgResp.ok) throw new Error(`openai image fetch ${imgResp.status}`);\n    const arr = await imgResp.arrayBuffer();\n    bytes = Buffer.from(arr);\n  } else {","sourceCodeStart":935,"sourceCodeEnd":971,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L935-L971","documentation":"Thrown by renderOpenAIImage after the images/generations fetch returns a non-2xx status. The tag is 'azure-openai' when detectAzureEndpoint flagged the base URL, otherwise 'openai'. The message includes resp.status and the first 240 chars of the response body so quota/auth/model errors are visible. This is the catch-all upstream HTTP failure for the OpenAI image path.","triggerScenarios":"Invalid or revoked API key (401); exhausted quota or billing issue (402/429); requesting a model the deployment does not expose (404 on Azure); rate limiting (429); transient 5xx from OpenAI/Azure; wrong baseUrl pointing at a non-OpenAI host.","commonSituations":"Free-tier key hitting rate limits; Azure deployment name mismatch; baseUrl typo; shared key revoked; model deprecated by provider.","solutions":["Read the embedded status and body snippet: 401/403 -> rotate/regenerate the key; 429 -> slow down or upgrade plan; 404 -> verify model id and Azure deployment name.","Confirm credentials.baseUrl is correct (omit it for public OpenAI; set the full Azure deployment URL for Azure).","Retry after the provider's Retry-Backoff for 429/5xx; the OpenAI image path does not auto-retry.","Check the provider status page if 5xx persists."],"exampleFix":"// before: wrong Azure deployment name -> 404\nOD_OPENAI_BASE_URL=https://my-resource.openai.azure.com/openai/deployments/wrong-name\n// after\nOD_OPENAI_BASE_URL=https://my-resource.openai.azure.com/openai/deployments/correct-deployment","handlingStrategy":"retry","validationCode":"function classifyOpenAIStatus(status: number): 'retry'|'fatal'|'config' {\n  if (status === 429 || status >= 500) return 'retry';\n  if (status === 401 || status === 403) return 'config';\n  return 'fatal';\n}","typeGuard":null,"tryCatchPattern":"try {\n  return await renderOpenAIImage(ctx, credentials);\n} catch (err) {\n  const m = err instanceof Error ? err.message : '';\n  const statusMatch = m.match(/(?:azure-openai|openai) (\\d{3}):/);\n  const status = statusMatch ? Number(statusMatch[1]) : 0;\n  if (status === 429 || status >= 500) throw new RetryableError(m);\n  if (status === 401 || status === 403) throw new ConfigError('rotate OpenAI key');\n  throw err;\n}","preventionTips":["Inspect the inlined status/body before retrying: only 429 and 5xx are worth retrying.","Keep the OpenAI model id and Azure deployment name in sync to avoid 404s.","Monitor quota in the OpenAI dashboard to pre-empt 402/429."],"tags":["network","media","openai","azure","http-status","upstream"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}