{"record":{"id":"f85b4b7e0cee76e1","repo":"nexu-io/open-design","slug":"no-imagerouter-api-key-configure-it-in-settings","errorCode":null,"errorMessage":"no ImageRouter API key — configure it in Settings or set OD_IMAGEROUTER_API_KEY","messagePattern":"no ImageRouter API key — configure it in Settings or set OD_IMAGEROUTER_API_KEY","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"apps/daemon/src/media/index.ts","lineNumber":985,"sourceCode":"    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 {\n    throw new Error('openai response had neither b64_json nor url');\n  }\n\n  const tag = azure ? 'azure-openai' : 'openai';\n  return {\n    bytes,\n    providerNote: `${tag}/${ctx.wireModel} · ${ctx.aspect} · ${bytes.length} bytes`,\n    suggestedExt: '.png',\n  };\n}\n\nasync function renderImageRouterImage(ctx: MediaContext, credentials: ProviderConfig): Promise<RenderResult> {\n  if (!credentials.apiKey) {\n    throw new Error(\n      'no ImageRouter API key — configure it in Settings or set OD_IMAGEROUTER_API_KEY',\n    );\n  }\n  const baseUrl = (credentials.baseUrl || IMAGEROUTER_DEFAULT_BASE_URL).trim();\n  const wireModel = (credentials.model || ctx.wireModel).trim();\n  const url = buildOpenAIImageUrl(baseUrl, false);\n  const body: Record<string, unknown> = {\n    prompt: ctx.prompt || 'A high-quality reference image.',\n    model: wireModel,\n    quality: 'auto',\n    size: imageRouterSizeFor(ctx.aspect, 'image'),\n    response_format: 'b64_json',\n    output_format: 'png',\n  };\n\n  const resp = await fetch(url, withMediaRequestInit(ctx, {\n    method: 'POST',\n    headers: {","sourceCodeStart":967,"sourceCodeEnd":1003,"githubUrl":"https://github.com/nexu-io/open-design/blob/5be4028344c2eb4c667c5a97bda8f750c5597ef7/apps/daemon/src/media/index.ts#L967-L1003","documentation":"Thrown at the top of renderImageRouterImage when credentials.apiKey is falsy. ImageRouter is an OpenAI-compatible gateway reached at IMAGEROUTER_DEFAULT_BASE_URL (https://api.imagerouter.io/v1/openai); the renderer refuses to call /images/generations without a Bearer key. The env var OD_IMAGEROUTER_API_KEY is the documented override.","triggerScenarios":"Selecting an ImageRouter-routed image model with no ImageRouter credential stored and no OD_IMAGEROUTER_API_KEY env var; key cleared from Settings but model still selected.","commonSituations":"User added an OpenAI key but ImageRouter needs its own; env var not exported in the daemon's process; trial key expired.","solutions":["Set OD_IMAGEROUTER_API_KEY in the daemon environment or add the key under Settings -> Media Providers -> ImageRouter.","Restart the daemon so the new env value is read.","Confirm with od media providers that ImageRouter shows a configured key.","Switch to the direct OpenAI provider if you have an OpenAI key instead."],"exampleFix":"// before\nod media generate --surface image --model <imagerouter-model> --prompt \"...\"\n// after\nexport OD_IMAGEROUTER_API_KEY=sk-ir-...\nod media generate --surface image --model <imagerouter-model> --prompt \"...\"","handlingStrategy":"validation","validationCode":"function ensureImageRouterCredential(creds: {apiKey?: string} | null): asserts creds is { apiKey: string } {\n  if (!creds?.apiKey) {\n    throw new Error('no ImageRouter API key — configure it in Settings or set OD_IMAGEROUTER_API_KEY');\n  }\n}\nensureImageRouterCredential(credentials);","typeGuard":"function hasImageRouterKey(c: {apiKey?:string} | null): c is { apiKey: string } {\n  return Boolean(c && typeof c.apiKey === 'string' && c.apiKey.length > 0);\n}","tryCatchPattern":null,"preventionTips":["Set OD_IMAGEROUTER_API_KEY in the daemon env, distinct from OPENAI_API_KEY.","Surface a missing-key badge next to ImageRouter-routed models in the picker.","Restart the daemon after setting env vars so the new value is read."],"tags":["media","provider-config","imagerouter","credentials","image"],"backgroundTag":null,"analyzedSha":"5be4028344c2eb4c667c5a97bda8f750c5597ef7","analyzedAt":"2026-08-12T12:03:58.812Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}