Skip to Content

Errors

Every failure has a stable code to branch on and says whether to retry. The codes and their HTTP statuses are the same for both APIs.

A failed request answers with an error object and no data:

Response · 400
{
  "error": {
    "code": "invalid_parameter",
    "message": "origin must be a 3-letter airport code such as SFO.",
    "param": "origin",
    "retry": "never",
    "request_id": "req_41ab9c"
  }
}

Prop

Type

What to do

One rule covers every code:

  • never: the same request will fail again. Change the request, or stop.
  • now: an immediate retry can succeed. Retry once or twice, with a short pause.
  • after: wait retry_after_s seconds, then retry.

Finding nothing is not an error. A search with no results is a success, with an empty list.

Codes

Each code always comes with the same HTTP status.

StatuscodeWhenretry
400invalid_parameterA field is missing, malformed or out of range. param names it.never
400invalid_bodyA POST body is not a JSON object, or is over 16 KB.never
401unauthenticatedNo key, or a key we don't know.never
403forbiddenThe key may not do this: it is revoked or expired, lacks live access or this product, or was used from outside your networks. A booking link that was changed also answers this.never
404not_foundNothing at this address.never
404search_not_foundNo search with that id for this key. Search again.never
405method_not_allowedThe address exists, but not for this method. The Allow header lists the methods it answers.never
410goneA booking link has expired.never
429rate_limitedOver one of your limits.after
502supplier_errorThe supplier failed the search.now
503search_capacityNo capacity to start new searches just now. Recent searches still answer.after
503service_unavailableKeys or limits can't be checked just now.after
504supplier_timeoutThe supplier took too long.now
500internal_errorA fault on our side. The detail is logged, never sent.now

A failed search stays failed

If reading a search by its search_id answers supplier_error or supplier_timeout, that search is over. Reading it again gives the same error. retry: "now" there means search the trip again.

Handle errors in code

Branch on error.retry, not on the status or the message:

call.mjs
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

export async function call(url, init = {}, attempts = 3) {
  for (let attempt = 1; ; attempt += 1) {
    const response = await fetch(url, {
      ...init,
      headers: { ...init.headers, "X-API-Key": process.env.VOYAGE_LABS_API_KEY },
    });
    const body = await response.json();
    if (response.ok) return body;

    const { code, message, retry, retry_after_s, request_id } = body.error;
    if (retry === "never" || attempt >= attempts) {
      throw new Error(`${code}: ${message} (request ${request_id})`);
    }
    await sleep(retry === "after" ? (retry_after_s ?? 1) * 1000 : 500 * attempt);
  }
}

Asking for help

Every answer, success or failure, carries a request id in meta.request_id or error.request_id, and in the X-Request-Id header. Log it. With it, we can find the exact request.

On this page