---
title: "Rename a Key, Edit Origins, Budget or Scope"
method: PATCH
path: "/keys/{id}"
tags: ["System"]
---

# Rename a Key, Edit Origins, Budget or Scope

`PATCH /keys/{id}`

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. On a publishable pk_ key neither bound can be cleared: null for either is refused with 400.

## Query parameters

- `fields` string
- `precision` integer

## Request body

- UpdateKey
  - `name` string
  - `origin_restriction` object
    - `type` 'server-only' | 'public'
    - `allowed_origins` string[]
  - `credits_cap_cycle` union
    - integer
    - unknown
  - `allowed_endpoints` union
    - string[]
    - unknown

## Response `200`

Successful calculation

- 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` unknown
    - `is_active` boolean, nullable
    - `origin_restriction` object, nullable
      - `type` string, nullable
      - `allowed_origins` string[], nullable
    - `credits_cap_cycle` number, nullable
    - `allowed_endpoints` string[], nullable

## Other responses

- `400` — Validation error
- `401` — Missing or invalid API key

## Changes

- **2026-09-21** `b64222844186` — 2 info
  - added the new optional `query` request parameter `fields`
  - added the new optional `query` request parameter `precision`
- **2026-09-14** `7b994706d03a` — 1 breaking
  - removed the enum value `allowlist` of the request property `origin_restriction/type`
- **2026-09-13** `e5364a7d5211` — 4 info
  - added the new optional request property `allowed_endpoints`
  - added the new optional request property `credits_cap_cycle`
  - added the optional property `data/allowed_endpoints` to the response with the `200` status
  - added the optional property `data/credits_cap_cycle` to the response with the `200` status
- **2026-09-12** `1d86c8ff3a62` — 1 info
  - endpoint added

[Change history](https://skmtc.dev/astroway/apis/astroway-calculation-api/changes/keys/:id/patch.md)

---

[API](https://skmtc.dev/astroway/apis/astroway-calculation-api.md) · [All operations](https://skmtc.dev/astroway/apis/astroway-calculation-api/llms.txt) · [OpenAPI document](https://skmtc.dev/astroway/apis/astroway-calculation-api/revisions/aa473bce3f00?raw)
