Saltar al contenido principal

Resumen

Usa este endpoint para actualizar el nombre, el límite de uso, los modelos permitidos, la caducidad o el estado de una API Key existente.

Cuerpo de la solicitud

Debe enviarse al menos un campo.
CampoTipoValor predeterminado / límitesNotas
statusenum-active, inactive, revoked
namestringlongitud 1-50Nombre visible actualizado
limitAmountnumber | nullmínimo 0, máximo de entrada 1000000null = ilimitado, 0 = cuota cero. Los valores positivos se normalizan a un límite almacenado que no puede superar 100000 USD equivalente.
limitCurrencyenumdefault USDSolo USD. Enviar CNY devuelve 400 currency_retired.
modelsstring[]-Lista actualizada de modelos lógicos permitidos
expiresAtstring | nulldatetime RFC3339null borra la caducidad

Notas

  • La eliminación dura no está soportada a propósito en Management API v1.
  • revoked es un estado terminal para el uso operativo normal; crea una nueva clave en lugar de esperar un futuro flujo de reactivación.

Ejemplo

curl -X PATCH "https://api.tokenlab.sh/v1/management/api-keys/key_abc123def456" \
  -H "Authorization: Bearer mt-your-management-token" \
  -H "Content-Type: application/json" \
  -d '{
    "status": "inactive",
    "limitAmount": 0
  }'

Solicitud / Respuesta

Usa el panel OpenAPI interactivo de arriba para ver el esquema exacto y los campos de respuesta.

Response example

{
  "id": "key_abc123def456",
  "name": "Backend Worker",
  "key_prefix": "sk-live...",
  "status": "inactive",
  "limit_amount": 0,
  "limit_amount_decimal": "0",
  "used_amount": 148.25,
  "used_amount_decimal": "148.25",
  "models": [
    "gpt-5-mini",
    "claude-3-7-sonnet"
  ],
  "expires_at": "2026-12-31T23:59:59.000Z",
  "last_used_at": "2026-07-08T03:12:45.000Z",
  "created_at": "2026-07-01T10:00:00.000Z"
}

Important fields

id
string
API key identifier used in follow-up Management API calls.
name
string
Display name for the API key.
key_prefix
string
Non-secret key prefix for display and support.
status
string
One of active, inactive, or revoked.
limit_amount
number | null
Spending cap in USD as a JSON number for display. null means unlimited.
limit_amount_decimal
string | null
Exact spending cap in USD as a decimal string. null means unlimited.
used_amount
number
Accumulated usage in USD as a JSON number for display.
used_amount_decimal
string
Exact accumulated usage in USD as a decimal string.
models
string[]
Per-key model allowlist. Empty array means no additional key-level model restriction.
expires_at
string | null
ISO timestamp when the key expires, or null for no expiry.
last_used_at
string | null
ISO timestamp for the most recent use, or null when unused.
created_at
string
ISO creation timestamp.