# Request IDs and headers

> Canonical URL: https://docs.mountaya.com/en/apis/conventions/headers/
> Last updated: 2026-11-27
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

The headers every Mountaya API request sends and every answer carries, how long answers are cached, and how long a request may run.

Every answer from every Mountaya API carries an `X-Request-Id`. Log it beside every failure, and quote it when you contact support: it finds your request among all the others.

## Request IDs

**cURL**

```bash
curl -s -i https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21 \
  -H "X-API-Key: $MOUNTAYA_PUBLISHABLE_KEY"
```

**TypeScript**

```typescript
import { Mountaya, MountayaApiError } from "@mountaya/client";

const mountaya = new Mountaya({
  credential: { publishableKey: process.env.MOUNTAYA_PUBLISHABLE_KEY ?? "" },
});

try {
  await mountaya.studio.itineraries.getItinerary({
    itinerary_id: "0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
  });
} catch (error) {
  if (!(error instanceof MountayaApiError)) {
    throw error;
  }
  console.log(error.status, error.requestId);
}
```

**Python**

```python
import os
import requests

answer = requests.get(
    "https://api.mountaya.com/v1/itineraries/0b6d1a4e-6d3f-4f7a-9c2e-1f0a5b8c3d21",
    headers={"X-API-Key": os.environ["MOUNTAYA_PUBLISHABLE_KEY"]},
    timeout=30,
)

print(answer.status_code, answer.headers["X-Request-Id"])
```

**Response**

```http
HTTP/1.1 404 Not Found
Cache-Control: private, no-store
Content-Type: application/json
X-Request-Id: 8ee0073c046aa0ff1b55b3b43515b870

{"errors":[{"message":"The requested resource was not found","extensions":{"code":"NOT_FOUND"}}]}
```

- Every answer on every API carries `X-Request-Id`: a success, a refusal, a redirect, and the opening of a stream alike. It is 32 lowercase hexadecimal characters, chosen by Mountaya. A value you send, in that header or in a trace context, is never echoed back.
- The TypeScript client carries it as `requestId` on every error the API answered, and ends the error's message with it. A `MountayaConnectionError` carries none, since no answer came. `onResponse` is told it for every answer.

## Request headers

| Header | Send it |
| --- | --- |
| `X-API-Key` | On every request: your publishable key, or your secret key on `POST /v1/sessions` |
| `X-Session-Token` | Where the operation or your organization needs a [session token](https://docs.mountaya.com/en/authentication.md) |
| `Idempotency-Key` | On every Map Studio API write. See [idempotency](https://docs.mountaya.com/en/apis/conventions/idempotency.md) |
| `If-Match` | To make a write conditional. See [conditional writes](https://docs.mountaya.com/en/apis/conventions/conditional-writes.md) |
| `Accept-Language` | To translate error messages and localized names |
| `Content-Type: application/json` | With every request body |

- The APIs authenticate with `X-API-Key` and `X-Session-Token` alone (and `X-Share-Token` for a share link). `Authorization: Bearer` is reserved for the Mountaya web application's own signed-in session.
- Request bodies are closed. A field an object does not declare is a `400` naming it, rather than being ignored, so a misspelled field is reported instead of silently dropped, for example `{"errors":[{"message":"property \"is_privat\" is unsupported","path":["request","body","is_privat"],"extensions":{"code":"VALIDATION_FAILED"}}]}`. A message raised by this validation is in English whatever `Accept-Language` asks for, so branch on `extensions.code` and `path` rather than on the text.
- Every string, number, and array a request carries is bounded, and the bound is declared where the field is. The few open maps by design, such as an agent run's `context`, declare how many entries and how many bytes they hold.
- A body that names a field twice, or holds text that is not valid UTF-8, is a `400`. Send each field once, spelled as the contract spells it.
- A query parameter an operation does not declare is a `400`.

## Response headers

| Header | Sent on |
| --- | --- |
| `X-Request-Id` | Every answer |
| `Retry-After` | Every `429` but a ceiling's (`LIMIT_REACHED`), and a `409` coded `IDEMPOTENCY_KEY_IN_USE` |
| `RateLimit`, `RateLimit-Policy` | Data API and Tile API answers. See [rate limits](https://docs.mountaya.com/en/apis/conventions/rate-limits.md#headers) |
| `ETag` | Every answer that returns a resource you can write conditionally, and a `412` |
| `Idempotent-Replayed` | `true` on a write's stored answer, replayed |
| `Location` | Every `201`, naming what was created, and every `308` |
| `WWW-Authenticate` | Every `401`, naming the credential to send |
| `Allow` | Every `405`, naming the methods the path takes |

Browsers on other origins can read all of these through CORS.

- `WWW-Authenticate` on every `401`: `ApiKey realm="mountaya"`, or `ShareToken realm="mountaya"` for a request made with a share token. It says what to send, never why the credential was refused.
- `RateLimit` and `RateLimit-Policy`: every Data API and Tile API answer the limits weighed, under a key or a share token.
- `ETag`: every answer that returns a resource carrying an `etag`, and the `412` that refuses a stale `If-Match`.
- A JSON answer that declares no `Cache-Control` of its own is `private, no-store`, and a stream is `no-cache`.
- A browser script on another origin can read `Retry-After`, `RateLimit`, `RateLimit-Policy`, `X-Request-Id`, `ETag`, `Location`, `Content-Disposition`, `Idempotent-Replayed`, and `Allow`: the APIs expose them to CORS.
- Canonical paths: a path written other than in its canonical form, with a trailing slash or an empty or dot segment, is answered `308 Permanent Redirect` to the canonical path, query string kept, for `GET` and `HEAD`. On the Map Studio API every other method is answered `404`, so a write is never redirected into a read. The Tile API takes no other method on any path, so it answers one there as on the canonical path: a write `405` before the credential is read, and an `OPTIONS` that is not a preflight `405` after it. The `308` carries `Location` and no error envelope.
- Methods: the Map Studio API answers `GET`, `POST`, `PATCH`, and `DELETE`, and there is no `PUT`: a toggled state is a resource of its own, and an action is a `POST` to a verb under the resource it acts on. The Tile API answers `GET` and `HEAD`, and the Data API `POST`. A method a path does not take is `405 Method Not Allowed`, and its `Allow` header names the methods it does.
- HEAD: every path that takes `GET` takes `HEAD`, answered with the headers the `GET` would carry and no body. On the Tile API a `HEAD` is limited as its `GET` is and never counted as usage, since it serves no tile, and neither is a specification. A `HEAD` on an event stream opens no subscription.

## Caching

Mountaya answers each request by the state it reads as the request arrives. Revoking a key or rotating a share link takes effect on the next request. Only public answers, such as a published itinerary or a public tile, may be stored by a shared cache, for at most a few minutes.

- Revoking a key, narrowing its scopes, taking an itinerary's or a zone's publication down, and removing or rotating a share link govern the very next request Mountaya answers.
- A shared cache between your visitors and Mountaya, such as a CDN or a corporate proxy, is another matter: an answer it already holds is served until the lifetime its `Cache-Control` names runs out. Only public answers are ever stored that way, and each says so:

| Answer | `Cache-Control` | Served from a shared cache for at most |
| --- | --- | --- |
| A published itinerary read, and its pace | `public, max-age=300, stale-while-revalidate=60` | 6 minutes |
| A published zone read | `public, max-age=300, stale-while-revalidate=60` | 6 minutes |
| The Map Studio API's layer catalog, `GET /v1/layers` | `public, max-age=86400, stale-while-revalidate=3600` | 25 hours |
| A public tile or specification on the Tile API, and its layer catalog under a key or a share token | `public, max-age=300` | 5 minutes |
| A base-map answer on the Tile API: a terrain style, its sources, sprites and glyphs, the elevation raster | as Mountaya's base-map provider labels it | the provider's lifetime |

- Every other answer is `private`, so no shared cache holds it.
- So a public tile a shared cache already holds may still be served for up to 5 minutes after its share link is rotated or removed.

## Timeouts

Each request runs under a time budget: 30 seconds, and 55 for an import. Past it, the API answers `504 Gateway Timeout`. Let your HTTP client wait a little longer than the budget, so it never abandons an answer that was coming.

- Each Map Studio and Tile API operation states its budget as `x-timeout-ms` in the reference: 30 seconds, and 55 on the import preview and the import, which route a whole file. Past it the request is answered `504 Gateway Timeout`, coded `GATEWAY_TIMEOUT`, whatever was in flight. On the Map Studio and Tile APIs a spent budget only ever replaces a 5xx, so an expiring deadline never turns a 404 into a 504.
- The Data API answers every request within 30 seconds: one still running then is a `504` coded `GATEWAY_TIMEOUT`, with no data, whatever had resolved, and its root fields count toward no allowance and no invoice.
- The four event streams run under no budget: a stream ends with the session token it was opened with instead, as [authentication](https://docs.mountaya.com/en/authentication.md#use-the-token) explains.
- The budget is per request, so retry a 504 once. Treat repeated timeouts as a signal to ask for less: fewer waypoints, a smaller bounding box, a narrower page.
- The TypeScript client waits an operation's `x-timeout-ms` plus five seconds by default before giving up on an attempt.

## In the TypeScript client

The [TypeScript client](https://docs.mountaya.com/en/sdks/typescript/client.md) applies all of this for you. It sends an `Idempotency-Key` with every write, waits out `Retry-After`, and follows cursors with `paginate`. Every error carries its `requestId`.

- The client mints an `Idempotency-Key` for every write that takes one and resends it on every retry, sends the `ifMatch` you pass, waits out `Retry-After`, walks a listing's cursors with `paginate` until one reads `null`, and reports each answer's request id, rate-limit state, and whether it was replayed to its `onResponse` hook, and the first two on every error.

## Next steps

- [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md): The error envelope and every code.
- [Versioning](https://docs.mountaya.com/en/apis/conventions/versioning.md): How the API changes, and how you hear about it.
