# AI

> Canonical URL: https://docs.mountaya.com/en/apis/map-studio/reference/ai/
> Last updated: 2026-11-26
> Rules for agents: https://docs.mountaya.com/llms.txt#rules-for-agents

The AI providers an organization can route agent runs through, and the credentials it has configured for them.

 There is no default provider: an organization with none configured cannot start a run, and `postAgentRun` answers `409` with `AI_PROVIDER_NOT_CONFIGURED`. Every operation here needs a session token beside the key.

## The AiProviderConfig object

The masked read view of an organization's AI provider configuration for the studio co-pilot. It never contains the credential: it carries the provider, the model, the base URL override if one is set, and a non-sensitive hint (the last four characters of the key) so an admin can recognize which key is in place. An organization with none configured reads `null` rather than this object, and cannot start an agent run.

- `provider` (string, required, one of: `anthropic`, `mistral`): The configured provider. It cannot be changed in place: delete the configuration and create one to switch providers.

- `model` (string, required): The configured model id, one of the provider's models in the catalog `getAiProviders` returns.

- `base_url` (string (uri) | null, required): The provider API base URL override, an absolute `https` URL, or null when completions go to the provider's default endpoint.

- `credential_hint` (string, required): A non-sensitive fragment of the configured credential, the last four characters of the provider key, shown so an admin can recognize the key without revealing it. Empty for a key shorter than 12 characters, of which four would be too large a part.

- `etag` (string, required): The version of the configuration, the one the `ETag` of a read of it carries, opaque and compared whole. Send it as `If-Match` to make `patchOrganizationAiProviderConfig` or `deleteOrganizationAiProviderConfig` conditional.

### An example AiProviderConfig

```json
{
  "provider": "anthropic",
  "model": "claude-sonnet-5-5",
  "base_url": null,
  "credential_hint": "IjkL",
  "etag": "\"d2\""
}
```

## List the AI provider catalog

### GET /v1/ai-providers

- Operation: `getAiProviders`
- Requires: scope `management` · acting user optional (a session token naming a member, or one minted without `user_id`)
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Returns the catalog of AI providers an organization may configure for the studio co-pilot: each provider's id, label, selectable model ids, and the credential fields it requires. The catalog is the same for every caller (no per-organization data) and is safe to cache. It asks no member role, so a session token is answered alike whoever it names, or, minted for `api`, with no user at all; one minted for `studio-embedded` without `user_id` is a `401`.

It is the vocabulary `postOrganizationAiProviderConfig` and `patchOrganizationAiProviderConfig` check a configuration against: the model is one of the provider's models, and the credential carries exactly the fields the provider names.

Like every read made with a session token naming a user, it is limited to 1200 a minute per user the token names and then to 6000 a minute per organization, and one made with a session token minted without `user_id` is held as the key alone is, to 600 a minute per client IP address and then 6000 per organization; past either, the answer is a `429` carrying `Retry-After`.

Requires a publishable key with the `management` scope AND a session token. A publishable key without a session token is not accepted here: a key written to be shipped in a browser cannot be sufficient on its own to read or change an organization's account.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The AI providers an organization may route agent runs through, and the credential fields each one needs.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (array of AiProviderCatalog, required)
  - `provider` (string, required, one of: `anthropic`, `mistral`): Stable identifier of the provider, and the value `postOrganizationAiProviderConfig` takes.
  - `label` (string, required): The provider's name as a person reads it. For display only; branch on `provider`.
  - `models` (array of string, required): The allow-list of model ids selectable for this provider.
  - `default_model` (string, required): The model id a fresh configuration seeds to: the one the picker preselects and the co-pilot falls back to. Always one of models.
  - `credential_fields` (array of AiCredentialField, required): The credential inputs this provider requires, in display order.
    - `key` (string, required): The stable credential map key to submit under AiProviderConfigParams.credential (for example "api_key"). A snake_case slug, bounded the way every other key on this surface is.
    - `label` (string, required): A human-readable field name for a configuration form.

**Errors** `400`, `401`, `403`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: Bad Request
- `401`: Unauthorized
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `management` scope. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Catalog only. It says which providers exist and what each one needs collected,
# never a stored credential.
curl -s https://api.mountaya.com/v1/ai-providers \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});
const admin = new MountayaAdmin(mountaya);

const { data } = await admin.organizations.getAiProviders();

console.log(data);
```

**Python**

```python
import requests

response = requests.get(
    "https://api.mountaya.com/v1/ai-providers",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": [
    {
      "provider": "anthropic",
      "label": "Anthropic",
      "models": [
        "claude-opus-5-5",
        "claude-sonnet-5-5"
      ],
      "default_model": "claude-sonnet-5-5",
      "credential_fields": [
        {
          "key": "api_key",
          "label": "API key"
        }
      ]
    }
  ]
}
```

## Retrieve an organization's AI provider configuration

### GET /v1/organizations/{organization_id}/ai-provider-config

- Operation: `getOrganizationAiProviderConfig`
- Requires: scope `management` · acting user optional (a session token naming a member, or one minted without `user_id`)
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Returns the organization's AI provider configuration for the studio co-pilot, masked: the provider, the model, the base URL override if one is set, and a non-sensitive hint of the credential. The credential itself is never returned.

An organization with no configuration is not a missing resource: it answers 200 with `data: null`, which is the state a client renders a setup prompt from, and which `postOrganizationAiProviderConfig` leaves.

- A session token minted for `api` without `user_id` is asked for no member role on this read; one minted for `studio-embedded` without `user_id` is the `401` a key alone gets. One that names a user is answered only while that user is a member of the organization, in any role, and is a 403 otherwise.

Like every read made with a session token naming a user, it is limited to 1200 a minute per user the token names and then to 6000 a minute per organization, and one made with a session token minted without `user_id` is held as the key alone is, to 600 a minute per client IP address and then 6000 per organization; past either, the answer is a `429` carrying `Retry-After`.

Requires a publishable key with the `management` scope AND a session token. A publishable key without a session token is not accepted here: a key written to be shipped in a browser cannot be sufficient on its own to read or change an organization's account.

**Path parameters**

- `organization_id` (string (uuid), in path, required): Identifier of the organization the operation acts on. A publishable key reaches only its own organization: any other identifier is a 403, whether or not it exists, so the parameter cannot be used to probe which organization ids exist.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The organization's AI provider configuration, or `data: null` when it has none. The credential is never returned; `credential_hint` shows enough to recognize which one is stored. `ETag` carries the configuration's `etag`, and is absent when `data` is null.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (AiProviderConfig | null, required): See [the AiProviderConfig object](https://docs.mountaya.com/en/apis/map-studio/reference/ai.md#ai-provider-config-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.

**Errors** `400`, `401`, `403`, `404`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: Bad Request
- `401`: Unauthorized
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `management` scope, or the path names an organization other than the key's own, whether or not it exists, or the session token names a user without a role in the organization, as a user who has left it, or whose invitation is still pending, is. Any role passes. A session token minted for `api` without `user_id` is asked for no role: it IS the organization's own backend's credential, minted server-side from its secret key, so it authorizes the read without a member behind it. One minted for `studio-embedded` without `user_id` is the `401` a key alone gets. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Answered only from Mountaya's web application: the path names an organization the person is not a member of, or one that does not exist. The two answer alike, so the path cannot be used to learn which organizations exist. Under a publishable key an identifier other than the key's organization is a `403` instead, whether or not it exists. An organization with no configuration answers `200` with `data: null`.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# The stored credential is never returned. `credential_hint` shows enough of it to
# recognize which key is configured.
curl -s https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});
const admin = new MountayaAdmin(mountaya);

const { data } = await admin.organizations.getOrganizationAiProviderConfig({ organization_id: "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b" });

console.log(data);
```

**Python**

```python
import requests

response = requests.get(
    "https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "provider": "anthropic",
    "model": "claude-sonnet-5-5",
    "base_url": null,
    "credential_hint": "IjkL",
    "etag": "\"d2\""
  }
}
```

## Configure an organization's AI provider

### POST /v1/organizations/{organization_id}/ai-provider-config

- Operation: `postOrganizationAiProviderConfig`
- Requires: scope `management` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: answers within 30000 ms or times out

Creates the organization's AI provider configuration for the studio co-pilot: the provider, the model, the credential, and optionally a base URL override. From then on the organization can start agent runs, which `postAgentRun` refuses while none is configured.

- Owner or admin only (403 otherwise).
- An organization has one configuration at most: creating one while one exists is a 409. Change it with `patchOrganizationAiProviderConfig`; the provider is fixed once configured, so switching providers is `deleteOrganizationAiProviderConfig` and then this.
- The model must be one of the provider's models, and the credential must carry every field the provider names and no other, each non-empty, as `getAiProviders` lists them; anything else is a 400 naming the field.
- The credential is write-only: it is encrypted at rest and never returned. The answer is the masked configuration, with a hint of the credential in its place.

Requires a publishable key with the `management` scope AND a session token naming a user, a member with the owner or admin role, whom the request acts as. A session token minted without `user_id` is refused with **401**, and a publishable key without a session token is not accepted here: a key written to be shipped in a browser cannot be sufficient on its own to read or change an organization's account.

**Webhook events** [`organization.ai_provider_config.created`](https://docs.mountaya.com/en/webhooks/events/organization-ai-provider-config.md#organization-ai-provider-config-created), recorded by the task `organization.ai_provider_config.create`.

**Path parameters**

- `organization_id` (string (uuid), in path, required): Identifier of the organization the operation acts on. A publishable key reaches only its own organization: any other identifier is a 403, whether or not it exists, so the parameter cannot be used to probe which organization ids exist.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The AI provider to route this organization's agent runs through, the model, and the credential to reach it with. The credential is write-only; reads return a hint, never the value.

- `provider` (string, in body, required, one of: `anthropic`, `mistral`): The AI provider to use. It cannot be changed afterwards: delete the configuration and create one to switch providers.

- `model` (string, in body, required): The model id to use. It must be one of the provider's models in the catalog `getAiProviders` returns, which is what decides whether a value is accepted; the ceiling below is the envelope bound, not the vocabulary.

- `base_url` (string (uri), in body, optional): A provider API base URL override, for routing completions through a gateway of the organization's own. Optional and not nullable: omit it to use the provider's default endpoint.

  Must be an absolute `https` URL on a public host, with no credentials in the URL and no query or fragment. Requests to this endpoint carry the configured provider credential, so plaintext `http`, loopback and private addresses, and internal-only names are all refused.

- `credential` (map of string, in body, required): The provider credential as a set of named fields. Each provider declares the fields it requires in the catalog `getAiProviders` returns; read them from there rather than assuming a shape. Every field the catalog names is sent, each non-empty, or the missing ones are a `400`; a field the catalog does not name is a `400` naming it. Write-only: never returned by any operation; a read answers with `credential_hint` instead.

  At most eight fields, each named in snake_case and holding at most 4096 characters.

**Response** `201`

The configuration as created. The credential just sent is not echoed back. `Location` names this same path, `/v1/organizations/{organization_id}/ai-provider-config`, since an organization has one configuration, and `ETag` carries its `etag`.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (AiProviderConfig, required): The masked read view of an organization's AI provider configuration for the studio co-pilot. It never contains the credential: it carries the provider, the model, the base URL override if one is set, and a non-sensitive hint (the last four characters of the key) so an admin can recognize which key is in place. An organization with none configured reads `null` rather than this object, and cannot start an agent run.

  See [the AiProviderConfig object](https://docs.mountaya.com/en/apis/map-studio/reference/ai.md#ai-provider-config-object).

Response headers:

- `Location`: The path of what the request created, relative to this host. A part of an itinerary is addressed under its itinerary, so a new segment's is `/v1/itineraries/{itinerary_id}/segments/{segment_id}`.
- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `403`, `404`, `409`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `management` scope, or the path names an organization other than the key's own, whether or not it exists, or the user the session token names is not a member of the key's organization, or is a member who is neither owner nor admin. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Answered only from Mountaya's web application: the path names an organization the person is not a member of, or one that does not exist. The two answer alike, so the path cannot be used to learn which organizations exist. Under a publishable key an identifier other than the key's organization is a `403` instead, whether or not it exists.
- `409`: The organization has an AI provider configuration already. Nothing is changed. Read it with `getOrganizationAiProviderConfig`, change its model, base URL or credential with `patchOrganizationAiProviderConfig`, or delete it with `deleteOrganizationAiProviderConfig` first to switch providers. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
curl -s -X POST https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Idempotency-Key: $(uuidgen)" \
  -H "Content-Type: application/json" \
  -d '{
    "provider": "anthropic",
    "model": "claude-sonnet-5-5",
    "credential": {
      "api_key": "sk-ant-api03-REPLACE_ME"
    }
  }'
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});
const admin = new MountayaAdmin(mountaya);

const { data } = await admin.organizations.postOrganizationAiProviderConfig({
  organization_id: "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
  body: {
    provider: "anthropic",
    model: "claude-sonnet-5-5",
    credential: { api_key: "sk-ant-api03-REPLACE_ME" },
  },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.post(
    "https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={
        "provider": "anthropic",
        "model": "claude-sonnet-5-5",
        "credential": {"api_key": "sk-ant-api03-REPLACE_ME"},
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 201:

```json
{
  "data": {
    "provider": "anthropic",
    "model": "claude-sonnet-5-5",
    "base_url": null,
    "credential_hint": "IjkL",
    "etag": "\"d2\""
  }
}
```

## Update an organization's AI provider configuration

### PATCH /v1/organizations/{organization_id}/ai-provider-config

- Operation: `patchOrganizationAiProviderConfig`
- Requires: scope `management` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Changes the organization's AI provider configuration, merged into what is stored: a field left out keeps its value, and an empty object changes nothing and answers the configuration as it stands.

- Owner or admin only (403 otherwise).
- `model` must be one of the configured provider's models in `getAiProviders`. `base_url` set to null clears the override, so completions go to the provider's default endpoint again.
- `credential` replaces the stored credential whole, carrying every field the configured provider names, each non-empty; omitted, the stored credential is kept, so the model can be changed without sending the key again. It is write-only and never returned.
- A `base_url` other than the one stored must come with `credential`: the stored credential is never sent to a host it was not stored for, so a new URL without it is a 400 with one entry at `["credential"]`, and nothing changes. A null `base_url`, which returns completions to the provider's own endpoint, keeps the stored credential.
- The provider is not a field here: switching providers is `deleteOrganizationAiProviderConfig` and then `postOrganizationAiProviderConfig`.
- With none configured there is nothing to change: the answer is a 409 coded `AI_PROVIDER_NOT_CONFIGURED`, whatever the body or `If-Match` says. It comes before any 400 this operation judges of the body (a model the provider lacks, a `base_url` refused or sent without `credential`, a credential of the wrong shape), since each is judged against the configured provider. Create one with `postOrganizationAiProviderConfig`.
- `If-Match` makes it conditional on the configuration's `etag`.
- A change takes effect at the next model call of every run, a run already in flight included.

Requires a publishable key with the `management` scope AND a session token naming a user, a member with the owner or admin role, whom the request acts as. A session token minted without `user_id` is refused with **401**, and a publishable key without a session token is not accepted here: a key written to be shipped in a browser cannot be sufficient on its own to read or change an organization's account.

**Webhook events** [`organization.ai_provider_config.updated`](https://docs.mountaya.com/en/webhooks/events/organization-ai-provider-config.md#organization-ai-provider-config-updated), recorded by the task `organization.ai_provider_config.update`.

**Path parameters**

- `organization_id` (string (uuid), in path, required): Identifier of the organization the operation acts on. A publishable key reaches only its own organization: any other identifier is a 403, whether or not it exists, so the parameter cannot be used to probe which organization ids exist.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Body**

The configuration fields to change. Every field is optional; an omitted field keeps its current value, and a null `base_url` clears it. A new `base_url` is the one field that needs another beside it: `credential`.

- `model` (string, in body, optional): The model id to use, one of the provider's models in the catalog `getAiProviders` returns. Optional and not nullable: omit it to keep the current model.

- `base_url` (string (uri) | null, in body, optional): A provider API base URL override, held to the rules `AiProviderConfigCreateParams` states for it. Omit it to keep the current one, and send null to clear it, which routes completions to the provider's default endpoint again.

  Requests to this endpoint carry the stored credential, so moving them to a new host is a change only someone holding that credential may make: a URL other than the one stored must come with `credential` in the same request, and without it the update is a `400` with one entry at `["credential"]` and nothing is changed. Null, which sends completions back to the provider's own endpoint, and the URL already stored need no credential.

- `credential` (map of string, in body, optional): A new provider credential, which REPLACES the stored one whole: every field the catalog names for the configured provider is sent, each non-empty, as on a create. Optional and not nullable: omit it to keep the stored credential, so the model can be changed without sending the key again. A `base_url` changed to a new URL is the exception, and requires it. Write-only: never returned by any operation.

  At most eight fields, each named in snake_case and holding at most 4096 characters.

**Response** `200`

The configuration after the change, with its new `etag` in `ETag`. A credential just sent is not echoed back.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (AiProviderConfig, required): The masked read view of an organization's AI provider configuration for the studio co-pilot. It never contains the credential: it carries the provider, the model, the base URL override if one is set, and a non-sensitive hint (the last four characters of the key) so an admin can recognize which key is in place. An organization with none configured reads `null` rather than this object, and cannot start an agent run.

  See [the AiProviderConfig object](https://docs.mountaya.com/en/apis/map-studio/reference/ai.md#ai-provider-config-object).

Response headers:

- `ETag`: The version of the resource this answer returns, an opaque strong tag in double quotes, equal to that resource's `etag` field. Send it back as `If-Match` to make a write conditional on nobody having changed the resource since. It changes whenever what this read returns changes; compare it whole and never parse it. Present on every answer that returns the resource, and on the `412` that refuses a stale `If-Match`.
- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `403`, `404`, `409`, `412`, `413`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `management` scope, or the path names an organization other than the key's own, whether or not it exists, or the user the session token names is not a member of the key's organization, or is a member who is neither owner nor admin. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Answered only from Mountaya's web application: the path names an organization the person is not a member of, or one that does not exist. The two answer alike, so the path cannot be used to learn which organizations exist. Under a publishable key an identifier other than the key's organization is a `403` instead, whether or not it exists. An organization with no configuration is the `409` coded `AI_PROVIDER_NOT_CONFIGURED`, not this.
- `409`: The organization has no AI provider configuration to change. The entry is coded `AI_PROVIDER_NOT_CONFIGURED`, the code `postAgentRun` answers for the same state, and nothing is changed: create one with `postOrganizationAiProviderConfig`. It is answered before any 400 this operation judges of the body, and whatever `If-Match` names, since there is neither a provider to judge the body against nor a version to compare it with. A request carrying the same `Idempotency-Key` as one still running is refused here too: its entry is coded `IDEMPOTENCY_KEY_IN_USE` and it carries `Retry-After`, after which the same request is answered with the first one's outcome. A request repeating the key of one whose answer cannot be replayed is refused here as well, its entry coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the answer was too large to keep whole, or the request failed with a `5xx` after its write was made. Either way that write was made, and `extensions.metadata` is the `ResponseMetadataIdempotentAnswer` naming how it was answered, so read the resource again rather than sending the write once more.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `413`: Payload Too Large
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Omit `credential` to keep the stored key. The provider cannot change here.
curl -s -X PATCH https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token" \
  -H "Content-Type: application/json" \
  -d '{"model": "claude-opus-5-5"}'
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});
const admin = new MountayaAdmin(mountaya);

const { data } = await admin.organizations.patchOrganizationAiProviderConfig({
  organization_id: "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b",
  body: { model: "claude-opus-5-5" },
});

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.patch(
    "https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    json={"model": "claude-opus-5-5"},
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": {
    "provider": "anthropic",
    "model": "claude-sonnet-5-5",
    "base_url": null,
    "credential_hint": "IjkL",
    "etag": "\"d2\""
  }
}
```

## Delete an organization's AI provider configuration

### DELETE /v1/organizations/{organization_id}/ai-provider-config

- Operation: `deleteOrganizationAiProviderConfig`
- Requires: scope `management` · acting user required (a session token naming a member) · an `Idempotency-Key` header, the same on every retry
- Behavior: idempotent, safe to retry · answers within 30000 ms or times out

Removes the organization's AI provider configuration, the stored credential with it. Without one the co-pilot cannot run for this organization's resources: `postAgentRun` answers 409 `AI_PROVIDER_NOT_CONFIGURED` until `postOrganizationAiProviderConfig` creates a new one, and a run already in flight ends with an error at its next model call.

- Owner or admin only (403 otherwise).
- Deleting is an act on the organization's state, so with none configured it answers 200 and changes nothing, whatever `If-Match` names: there is no configuration left for the condition to protect.
- `If-Match` makes it conditional on the configuration's `etag`, so a configuration somebody changed since it was read is not deleted unseen.

Requires a publishable key with the `management` scope AND a session token naming a user, a member with the owner or admin role, whom the request acts as. A session token minted without `user_id` is refused with **401**, and a publishable key without a session token is not accepted here: a key written to be shipped in a browser cannot be sufficient on its own to read or change an organization's account.

**Webhook events** [`organization.ai_provider_config.deleted`](https://docs.mountaya.com/en/webhooks/events/organization-ai-provider-config.md#organization-ai-provider-config-deleted), recorded by the task `organization.ai_provider_config.delete`.

**Path parameters**

- `organization_id` (string (uuid), in path, required): Identifier of the organization the operation acts on. A publishable key reaches only its own organization: any other identifier is a 403, whether or not it exists, so the parameter cannot be used to probe which organization ids exist.

**Headers**

- `Idempotency-Key` (string, in header, optional): A value the caller chooses once per logical write and sends again, unchanged, on every retry of it, so a write whose answer was lost runs at most once. A UUID is the usual choice; any 1 to 255 printable ASCII characters without a space are accepted. The key is held for 12 hours, for the credential that sent it (the publishable key and the user its session token names) and for this operation.

  The first request runs. A request repeating the key with the same method, path, query and body, sent as the same media type, is answered with the first one's stored status and body, its `Location` and `ETag` included, and carries `Idempotent-Replayed: true`; nothing runs a second time and no limit is charged again. `Content-Type` is compared as the media type it names, with its `charset`, rather than as the header was written, so the letter case of the type and the spacing around its parameters do not make two requests different. `If-Match` is not compared: a key sent again after a `412`, with a fresh tag, is answered with that same `412`, so a write retried with a new tag takes a new key. Every answer below `500` other than a `429` is stored that way, a refusal included, so a retried request that was refused is refused again in the same words. A request refused before the write is reached stores nothing, and a retry with the same key runs again: every `401`, and every `413` refusing a body over the operation's ceiling. The `413` that `postItineraryPreview` answers for the source it has read, a file or a track too large, is stored as any other refusal is.

  A `5xx` answered before anything was written stores nothing and releases the key: a retry with the same key runs again. A `5xx` answered after the write was made keeps the key, and a request repeating it is a `409` whose entry is coded `IDEMPOTENCY_ANSWER_UNAVAILABLE`, as is a request repeating the key of an answer too large to store whole. Either way the write was made: the `409` carries no `Location`, and its `extensions.metadata` (`ResponseMetadataIdempotentAnswer`) names the `status` the first request was answered with and, where that answer carried them, its `location` and `etag`. Read the resource again rather than sending the write once more, which is answered the same way.

  The same key with a different request is a `400` at `["request", "headers", "Idempotency-Key"]`, and nothing runs, whether the first request is still running or was answered. The same request while its first one is still running is a `409` whose entry is coded `IDEMPOTENCY_KEY_IN_USE`, carrying `Retry-After`: send it again once that has passed. Without the header a write runs every time it is sent, which is harmless on the writes `x-idempotent` marks safe to repeat and creates a second resource on the others. A stream's answer is never stored.

  Keys are kept on a best-effort basis. While Mountaya cannot read or record them, a write runs as if it carried no key, so a retry sent in that moment can run it a second time.

- `If-Match` (string, in header, optional): Makes the write conditional on the resource still being the version the caller read: the `ETag` an earlier answer carried, which is also that resource's `etag` field, or `*` for any version. When the resource has changed since, the write is refused with `412` `PRECONDITION_FAILED`, nothing is changed, and the answer carries the current `ETag`, so the caller reads the resource again and decides. Omitted, the write is unconditional and the last write wins.

  One strong tag in double quotes, or `*`. A list of tags, a weak tag (`W/`) or any other spelling is a `400` naming the header. A resource the caller cannot see is answered `404` before the condition is asked, so a stale tag never tells a caller anything a read would not.

Also takes `Accept-Language`, as every operation of this API does: the [overview](https://docs.mountaya.com/en/apis/map-studio/reference.md) describes it.

**Response** `200`

The AI provider configuration is removed, or there was none. The organization has no provider until a new one is created, so `postAgentRun` answers 409 `AI_PROVIDER_NOT_CONFIGURED`. `data` is null.

- `extensions` (object): Top-level extensions map for 2xx responses. Mirrors the GraphQL-spec response extensions: a free-form map for response-scoped metadata.
  - `metadata` (object): Response-scoped metadata. Its shape is per-operation: the operation that emits it names the schema, and an operation that documents none never emits this field.

- `data` (any | null, required): Always null: this operation answers with no payload.

Response headers:

- `Idempotent-Replayed`: `true` when this answer is the stored answer to an earlier request carrying the same `Idempotency-Key`, replayed rather than run again. Absent on an answer that ran.

**Errors** `400`, `401`, `403`, `404`, `409`, `412`, `429`, `500`, `504`. See [Errors](https://docs.mountaya.com/en/apis/conventions/errors.md).

- `400`: The request was malformed, or a field failed validation: each entry names what, a field-level one at its `path`. The same `Idempotency-Key` sent with another request is refused here too, at `["request", "headers", "Idempotency-Key"]`. A refusal the write itself made is stored for its key, so a repeat of the key is refused again in the same words, marked `Idempotent-Replayed: true`.
- `401`: Unauthorized
- `403`: The credential is valid and this operation is not open to it: the key does not carry the `management` scope, or the path names an organization other than the key's own, whether or not it exists, or the user the session token names is not a member of the key's organization, or is a member who is neither owner nor admin. A user outside the organization and a member without the role answer alike. The blanket refusal in the [order of checks](https://docs.mountaya.com/en/apis/conventions/errors.md#which-refusal-you-get-first), an `Origin` or `Referer` the organization does not allow, answers here as well.
- `404`: Answered only from Mountaya's web application: the path names an organization the person is not a member of, or one that does not exist. The two answer alike, so the path cannot be used to learn which organizations exist. Under a publishable key an identifier other than the key's organization is a `403` instead, whether or not it exists. An organization with no configuration answers `200`.
- `409`: `IdempotencyKeyInUse`, given in full at the end of this page.
- `412`: `PreconditionFailed`, given in full at the end of this page.
- `429`: `TooManyRequests`, given in full at the end of this page.
- `500`: Internal Server Error
- `504`: Gateway Timeout

**cURL**

```bash
# Clears the provider and the stored credential together. A run already in flight
# ends with an error at its next model call, and a new one is refused with 409.
curl -s -X DELETE https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config \
  -H "X-API-Key: pk_your_publishable_key" \
  -H "X-Session-Token: sess_your_session_token"
```

**TypeScript**

```typescript
import { Mountaya } from "@mountaya/client";
import { MountayaAdmin } from "@mountaya/client/admin";

const mountaya = new Mountaya({
  credential: { publishableKey, sessionToken },
});
const admin = new MountayaAdmin(mountaya);

const { data } = await admin.organizations.deleteOrganizationAiProviderConfig({ organization_id: "d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b" });

console.log(data);
```

**Python**

```python
import requests
import uuid

response = requests.delete(
    "https://api.mountaya.com/v1/organizations/d5a83e17-92c6-4b0f-a7d3-1e6482f9c05b/ai-provider-config",
    headers={
        "X-API-Key": "pk_your_publishable_key",
        "X-Session-Token": "sess_your_session_token",
        "Idempotency-Key": str(uuid.uuid4()),
    },
    timeout=30,
)
response.raise_for_status()
print(response.json()["data"])
```

Response 200:

```json
{
  "data": null
}
```

**Error answers the operations of this page share**

- `TooManyRequests` (`429`): A limit on this operation's requests is spent: the [rate limits](https://docs.mountaya.com/en/apis/conventions/rate-limits.md) page lists every one, the unknown publishable keys one address may present among them, and the operation's description names any of its own. The request was counted and nothing was done. `Retry-After` says how long until the limit lifts; wait that long, with a little jitter of your own, and send the request again. Where the operation takes an `Idempotency-Key`, a write sent again with the same key runs once.
- `PreconditionFailed` (`412`): `If-Match` named a version the resource has moved on from: somebody changed it after the caller read it. Nothing was changed. The one entry is coded `PRECONDITION_FAILED`, and `ETag` carries the current version, so read the resource again, decide whether the change still applies, and send it with the new tag. Retrying with the same tag is refused the same way. A resource the caller cannot see is answered `404` before the condition is asked, and a write refused for any other reason is refused for that reason first.
- `IdempotencyKeyInUse` (`409`): The `Idempotency-Key` this request carries is one an earlier request was sent with, and the answer to that one cannot be given here. Nothing was done by this request. Its entry says which. `IDEMPOTENCY_KEY_IN_USE`: the first request is still running. Wait the `Retry-After` this carries and send the same request again, which is then answered with the first request's outcome. `IDEMPOTENCY_ANSWER_UNAVAILABLE`: the first request's write was made, and its answer cannot be given again, because it was too large to keep whole, because the request failed with a `5xx` after the write was made, or because it carried a credential shown only once, which is never kept. `extensions.metadata` names the status it was answered with, and its `Location` and `ETag` where it carried them; a create whose operation says so names what it made there after a `5xx` too. Read the resource again rather than sending the write once more, which is answered the same way. A credential cannot be read again: where the operation says its answer carries one, the one it created is at `metadata.location`, so revoke that one and create another.
