Skip to main content
POST
Create a model-access policy

Authorizations

Authorization
string
header
required

A Barndoor API key, sent as Authorization: Bearer <key>. Keys are prefixed bdai_ and are opaque — do not attempt to decode one. Interchangeable with an OAuth 2.0 access token.

Scopes

openid

Issue an OIDC ID token identifying the caller.

profile

Read the caller's basic profile claims.

email

Read the caller's email address.

Body

application/json
name
string
required
policy_type
string
required
scope_type
string
required
targets
object[]
required

A single restriction target inside a [ModelAccessPolicy].

Targets answer the question "what is being allowed/denied?" — distinct from scope_type, which answers "who is the policy applied to?". A policy's targets list is OR-ed when matching: a request matches the policy if any one of its targets matches the (provider, model) pair.

Serialised to JSONB with a kind discriminator so it round-trips cleanly through the admin REST API.

ModelAlias matches against the literal model field in the request. Model matches against the resolved upstream model — i.e. the underlying model the routed mapping points at. The two are distinct because the admin UI lets admins pick along either dimension: a goto alias fanned out across providers is best expressed with ModelAlias, while "block any request that ends up at gpt-4o-mini regardless of the alias used" is best expressed with Model (so it fires even when goto resolves to gpt-4o-mini).

change_note
string | null

Optional free-text note explaining why this policy was created (BCP-3998). Surfaced on the row and mirrored into the audit event.

scope_id
string<uuid> | null

Single-entity form of scope_ids, kept for existing clients. Send one or the other; when both are sent scope_id must be the first element of scope_ids.

scope_ids
string<uuid>[] | null

Every user / project / API key / agent the policy applies to (BCP-5001). The policy applies when any one of them matches the caller. Empty or omitted means not bound to a specific entity.

scope_value
string | null

Single-entity form of scope_values; same rules as scope_id.

scope_values
string[] | null

Every role / group name the policy applies to (BCP-5001). Same any-of semantics as scope_ids.

traffic_type
string

Response

The created record

An admin-API response for an entity whose core type lives in ai_governance and so cannot carry portal-only columns.

TokenBudget and RateLimitPolicy are read by the enforcement path on every request; hanging five display-only fields off them would put portal concerns in the hot path's type and force every governance consumer to carry them. Wrapping instead keeps the enforcement reads (get_enabled_by_org and friends) returning the bare governance type, while the admin reads return this.

Both halves are #[serde(flatten)], so the wire shape stays the flat object the portal already consumes — same choice AdminModelPricing makes.

enabled
boolean
required
id
string<uuid>
required
name
string
required
org_id
string<uuid>
required
policy_type
string
required
scope_ids
string<uuid>[]
required

Every UUID-keyed entity (user / project / api_key / agent) the policy is bound to (BCP-5001). Empty means unbound: the policy is not pinned to a specific entity of its scope type.

scope_type
string
required
scope_values
string[]
required

Every role / group name the policy is bound to (BCP-5001). Empty means unbound.

targets
object[]
required

A single restriction target inside a [ModelAccessPolicy].

Targets answer the question "what is being allowed/denied?" — distinct from scope_type, which answers "who is the policy applied to?". A policy's targets list is OR-ed when matching: a request matches the policy if any one of its targets matches the (provider, model) pair.

Serialised to JSONB with a kind discriminator so it round-trips cleanly through the admin REST API.

ModelAlias matches against the literal model field in the request. Model matches against the resolved upstream model — i.e. the underlying model the routed mapping points at. The two are distinct because the admin UI lets admins pick along either dimension: a goto alias fanned out across providers is best expressed with ModelAlias, while "block any request that ends up at gpt-4o-mini regardless of the alias used" is best expressed with Model (so it fires even when goto resolves to gpt-4o-mini).

traffic_type
string
required
scope_id
string<uuid> | null

First element of [Self::scope_ids], kept for clients that predate multi-entity scopes (BCP-5001). Never read for matching when scope_ids is non-empty -- see [Self::bound_ids].

scope_value
string | null

First element of [Self::scope_values]; same compatibility role as scope_id.

created_by_email
string | null
created_by_name
string | null
created_by_user_id
string<uuid> | null
last_change_note
string | null

Optional free text explaining why the last change was made ("Raised for the Q3 batch job", "Vendor deprecated the old endpoint").

Admin-authored and rendered in the portal, so it is untrusted input: length-capped here, escaped on render.

last_modified_at
string<date-time> | null

When the change named by last_modified_by_* happened.

Its own column rather than the row's updated_at, because updated_at is bumped by writes nobody is attributed for -- pairing the two would date a named admin's edit to a background job's clock. See the V75 migration for the full reasoning.

last_modified_by_email
string | null
last_modified_by_name
string | null
last_modified_by_user_id
string<uuid> | null