nexu-io/open-design · error · Error

${providerTag} response had no data[0]

Error message

${providerTag} response had no data[0]

What it means

Thrown by bytesFromOpenAICompatibleData when the parsed JSON lacks a non-empty data array (or data[0] is null). Same contract expectation as the first-party path — OpenAI-compatible gateways must return {data:[{...}]} — generalized via providerTag so any compatible integration surfaces the same defect.

Source

Thrown at apps/daemon/src/media/index.ts:1139

  if (!baseUrl || !model) return false;
  return model === ctx.model || model === ctx.wireModel;
}

async function parseOpenAICompatibleJson(resp: Response, providerTag: string): Promise<any> {
  const text = await resp.text();
  if (!resp.ok) {
    throw new Error(`${providerTag} ${resp.status}: ${truncate(text, 240)}`);
  }
  try {
    return JSON.parse(text);
  } catch {
    throw new Error(`${providerTag} non-JSON response: ${truncate(text, 200)}`);
  }
}

async function bytesFromOpenAICompatibleData(data: any, providerTag: string, requestInit: MediaRequestInit = {}): Promise<Buffer> {
  const entry = data && Array.isArray(data.data) ? data.data[0] : null;
  if (!entry) throw new Error(`${providerTag} response had no data[0]`);
  if (typeof entry.b64_json === 'string' && entry.b64_json) {
    const raw = entry.b64_json.includes(',')
      ? entry.b64_json.slice(entry.b64_json.indexOf(',') + 1)
      : entry.b64_json;
    return Buffer.from(raw, 'base64');
  }
  if (typeof entry.url === 'string' && entry.url) {
    const mediaResp = await fetch(entry.url, requestInit);
    if (!mediaResp.ok) {
      throw new Error(`${providerTag} media fetch ${mediaResp.status}`);
    }
    const arr = await mediaResp.arrayBuffer();
    return Buffer.from(arr);
  }
  throw new Error(`${providerTag} response had neither b64_json nor url`);
}

function imageRouterSizeFor(aspect: string | undefined, surface: 'image' | 'video'): string {

View on GitHub (pinned to 5be4028344)

Solutions

  1. Log the full parsed JSON to identify the actual envelope used by the gateway.
  2. Choose a gateway that faithfully implements the OpenAI images schema, or extend bytesFromOpenAICompatibleData to handle the alternate envelope.
  3. Switch to a model id on the gateway that returns the standard {data:[...]} shape.
  4. Confirm the gateway is not returning a moderation/error envelope under HTTP 200.

Example fix

// before: gateway returns {images:[{b64_json:'...'}]}
// after: either reconfigure the gateway or extend the parser to read data.images
if (!entry && Array.isArray(data.images)) entry = data.images[0];
Defensive patterns

Strategy: type-guard

Validate before calling

function hasCompatibleDataArray(data: unknown): data is { data: unknown[] } {
  return Boolean(data && typeof data === 'object' && Array.isArray((data as any).data) && (data as any).data.length > 0);
}

Type guard

function hasCompatibleDataArray(data: unknown): data is { data: unknown[] } {
  return Boolean(data && typeof data === 'object' && Array.isArray((data as any).data) && (data as any).data.length > 0);
}

Try / catch

try {
  return await bytesFromOpenAICompatibleData(data, providerTag, requestInit);
} catch (err) {
  const m = err instanceof Error ? err.message : '';
  if (m.endsWith('response had no data[0]')) {
    throw new ConfigError(`${providerTag}: response did not contain a data[] entry. Verify gateway schema.`);
  }
  throw err;
}

Prevention

When it happens

Trigger: Gateway returns an error envelope with HTTP 200; response schema differs from OpenAI's (e.g. {images:[...]} instead of {data:[...]}); empty data array on a no-op success.

Common situations: Compatible gateway that does not fully implement the OpenAI schema; preview/beta endpoint with a different envelope; gateway that wraps responses in an outer metadata object.

Related errors


AI-assisted analysis of nexu-io/open-design@5be4028344 (2026-08-12). Data as JSON: /api/errors/dc650fe69f7f24f9. Report an issue: GitHub.