Перейти до вмісту
AstroWay/api v2.190.0 · docs
усі системи в нормі

Rename a Key, Edit Origins, Budget or Scope

PATCH
/keys/{id}
request.sh
curl -X PATCH https://api.astroway.info/v1/keys/{id} \
-H "X-Api-Key: aw_live_..." \
-H "Content-Type: application/json" \
-d '{ "name": "site-widget", "credits_cap_cycle": 5000, "allowed_endpoints": [ "embed/*" ], "origin_restriction": { "type": "public", "allowed_origins": [ "example.com", "*.example.com" ] } }'

Rename a key, rewrite the origin list of a publishable key, set a per-key credit budget, limit the key to a subset of endpoints, or any combination. The class is fixed at creation: a pk_ key cannot become server-only, and a secret key cannot be given a list, so either request is refused with 400 rather than quietly rewritten. A new list takes effect at once and the key string does not change. credits_cap_cycle caps what this one key may spend per billing cycle, which credits alone do not, since they pool across the account; null clears it and a call over the cap answers 429 KEY_BUDGET_EXHAUSTED without falling through to overage. allowed_endpoints takes paths under /v1, exact (“chart”) or a namespace (“embed/*”); null removes the limit and a call outside the list answers 403 ENDPOINT_NOT_IN_SCOPE.

Media type application/json
object
name
string
>= 1 characters <= 100 characters
origin_restriction
object
type
string
default: public
Allowed values: server-only public
allowed_origins
Array<string>
<= 20 items
credits_cap_cycle
Any of:
integer
<= 1000000000
allowed_endpoints
Any of:
Array<string>
<= 30 items
Example
{
"name": "site-widget",
"credits_cap_cycle": 5000,
"allowed_endpoints": [
"embed/*"
],
"origin_restriction": {
"type": "public",
"allowed_origins": [
"example.com",
"*.example.com"
]
}
}

Successful calculation

Media type application/json
object
ok
boolean
data
object
id
number
nullable
api_key_masked
string
nullable
name
string
nullable
plan
string
nullable
rate_limit
number
nullable
credits_limit
number
nullable
credits_used
number
nullable
created_at
string
nullable
last_used_at
nullable
is_active
boolean
nullable
origin_restriction
object
type
string
nullable
allowed_origins
Array<string>
nullable
credits_cap_cycle
number
nullable
allowed_endpoints
Array<string>
nullable
Example
{
"ok": true,
"data": {
"id": 42,
"api_key_masked": "pk_live…e5f6",
"name": "site-widget",
"plan": "free",
"rate_limit": 10,
"credits_limit": 10000,
"credits_used": 0,
"created_at": "2026-08-22T21:05:14.335Z",
"last_used_at": null,
"is_active": true,
"origin_restriction": {
"type": "public",
"allowed_origins": [
"example.com",
"*.example.com"
]
},
"credits_cap_cycle": 5000,
"allowed_endpoints": [
"embed/*"
]
}
}

Validation error

Media type application/json
Example
{
"ok": false,
"error": {
"code": "INVALID_INPUT",
"message": "Validation failed: date: Date must be YYYY-MM-DD",
"details": [
{
"path": "date",
"message": "Date must be YYYY-MM-DD"
}
]
}
}

Missing or invalid API key

Media type application/json
Example
{
"ok": false,
"error": {
"code": "INVALID_API_KEY",
"message": "Invalid API key"
}
}
Корисно?