Apply a model-provider choice in one transaction

Preview

Not yet in the latest release.

One write for a provider choice: the credential its models run on (an existing organization credential { id }, a new organization API key — the POST /api/model-provider-credentials body without owner_type —, or null for models each member serves with their own credential, providerId then naming the service), the models to create (add), the ones to switch on (enable) and off (disable), and the default (default_model_id, the modelId of a model of this choice). Applied in that order — the key, the models, the switches on, the default, the switches off — inside ONE transaction: either all of it is written or none. Every entry is checked as its own route would check it (POST /api/models, PATCH /api/models/{id}, PUT /api/models/default); refusals come back together as 400 validation_failed with one errors[] item per entry (field: add.<i>, enable.<i>, disable.<i>, default_model_id; code: that route's own, or model_not_in_choice for a model that does not run on the choice's credential), and nothing is written. Requires models:write, and model-provider-credentials:write to mint an organization key (the rule of POST /api/model-provider-credentials with owner_type: org; :connect alone does not suffice), rate-limited like that route. Accepts Idempotency-Key: a retry with the same key and body replays the first response.

POST/api/models/apply

Authorization

better-auth.session_token<token>

Cookie session from Better Auth. Requires X-Org-Id header for org-scoped routes.

In: cookie

Header Parameters

X-Org-Id?string

Organization ID. Required for cookie auth. Not needed for API key auth (org resolved from key).

Formatuuid
Idempotency-Key?string

Unique key for idempotent requests (max 255 chars). Prevents duplicate resource creation on retries. Scoped to the organization, the space and the authenticated caller — the member or end-user, the API key or OAuth client, the auth method — so the same key sent by another caller is a new request, never a replay. Only a request that executed — a 2xx — is stored, for 24 hours. A repeat by the same caller with the same method, URL and body re-serves that response with Idempotent-Replayed: true: current permissions are checked again, a run is re-read under current visibility, and its warnings items carry no bearer connect link (connect_url, expiresAt, packageId). A refusal (4xx) or failure (5xx) is never stored: the key is released and a retry is judged again, so a 409 missing_integration_connection retried after connecting launches the run. While a response is stored, the same key with a different method, URL or body is 422 idempotency_conflict; a concurrent duplicate is 409 idempotency_in_progress. This operation honours the header because it declares this parameter — operations that do not declare it refuse the header with 400 idempotency_not_supported rather than silently ignoring it (see the “Idempotency” section of the API description).

Lengthlength <= 255

Request Body

application/json

curl -X POST "https://your-instance/api/models/apply" \  -H "Content-Type: application/json" \  -d '{    "credential": {      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08"    }  }'
{
  "object": "model_choice",
  "credential_id": "string",
  "models": [
    {
      "id": "string",
      "label": "string",
      "apiShape": "string",
      "providerId": "string",
      "provider_name": "string",
      "pi_provider": "string",
      "pi_dialect": {},
      "base_url": "string",
      "modelId": "string",
      "generation": {
        "temperature": "supported",
        "reasoning": {
          "supported": "supported",
          "temperature_compatible": "supported",
          "adaptive": true,
          "levels": {
            "property1": "supported",
            "property2": "supported"
          },
          "off": "disables"
        }
      },
      "input": [
        "text"
      ],
      "contextWindow": 0,
      "maxTokens": 0,
      "reasoning": true,
      "enabled": true,
      "is_default": true,
      "needs_reconnection": true,
      "aliased": true,
      "iconUrl": "string",
      "source": "built-in",
      "credentialId": "string",
      "binding": "system",
      "billed_to": "system",
      "cost": {
        "input": 0,
        "output": 0,
        "cacheRead": 0,
        "cacheWrite": 0,
        "tiers": [
          {
            "inputTokensAbove": 1,
            "input": 0,
            "output": 0,
            "cacheRead": 0,
            "cacheWrite": 0
          }
        ]
      },
      "created_by": "string",
      "createdAt": "2019-08-24T14:15:22Z",
      "updatedAt": "2019-08-24T14:15:22Z"
    }
  ],
  "default_model_id": "string"
}

{
  "type": "https://docs.appstrate.dev/errors/validation-failed",
  "title": "Validation Failed",
  "status": 400,
  "detail": "name: Invalid input: expected string, received undefined (+2 more)",
  "code": "validation_failed",
  "request_id": "req_abc123",
  "errors": [
    {
      "field": "name",
      "code": "required",
      "message": "Invalid input: expected string, received undefined"
    },
    {
      "field": "email",
      "code": "invalid_format",
      "message": "Invalid email address"
    },
    {
      "field": "age",
      "code": "invalid_type",
      "message": "Invalid input: expected number, received string"
    }
  ]
}

{
  "type": "https://docs.appstrate.dev/errors/unauthorized",
  "title": "Unauthorized",
  "status": 401,
  "detail": "Invalid or missing session",
  "code": "unauthorized",
  "request_id": "req_abc123"
}
{
  "type": "https://docs.appstrate.dev/errors/forbidden",
  "title": "Forbidden",
  "status": 403,
  "detail": "Insufficient permissions",
  "code": "forbidden",
  "request_id": "req_abc123"
}
{
  "type": "https://docs.appstrate.dev/errors/idempotency-conflict",
  "title": "Idempotency Conflict",
  "status": 422,
  "detail": "This Idempotency-Key was already used with a different method, URL or body. Use a new key for different requests.",
  "code": "idempotency_conflict",
  "request_id": "req_abc123"
}
{
  "type": "https://docs.appstrate.dev/errors/rate-limited",
  "title": "Rate Limited",
  "status": 429,
  "detail": "Too many requests. Please try again shortly.",
  "code": "rate_limited",
  "request_id": "req_abc123",
  "retry_after": 30
}
{
  "type": "http://example.com",
  "title": "string",
  "status": 0,
  "detail": "string",
  "instance": "string",
  "code": "string",
  "request_id": "string",
  "param": "string",
  "retry_after": 0,
  "errors": [
    {
      "field": "string",
      "code": "string",
      "message": "string",
      "title": "string",
      "line": 1,
      "column": 1,
      "candidate_connections": [
        {
          "id": "string",
          "label": "string",
          "account_id": "string",
          "owned_by_actor": true,
          "needs_reconnection": true,
          "scopes_granted": [
            "string"
          ],
          "missing_scopes": [
            "string"
          ]
        }
      ],
      "connection_id": "string",
      "missing_scopes": [
        "string"
      ],
      "remedy": "new_connection",
      "owned_by_actor": true,
      "required_scopes": [
        "string"
      ],
      "auth_key": "string",
      "required_auth_key": "string",
      "available_auth_keys": [
        "string"
      ],
      "source": "admin_pin",
      "connect_url": "http://example.com",
      "expiresAt": "2019-08-24T14:15:22Z",
      "packageId": "string"
    }
  ]
}