> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tokenlab.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# تحديث مفتاح API

> يحدّث مفتاح API مستخدم موجودًا في المؤسسة الحالية.

## نظرة عامة

استخدم هذا الـ endpoint لتحديث الاسم أو حد الاستخدام أو النماذج المسموح بها أو وقت الانتهاء أو الحالة الخاصة بمفتاح API موجود.

## جسم الطلب

يجب أن يتضمن طلب PATCH حقلًا واحدًا على الأقل.

| الحقل           | النوع          | القيم الافتراضية / القيود                      | الوصف                                                                                                                       |
| --------------- | -------------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `status`        | enum           | -                                              | `active`, `inactive`, `revoked`                                                                                             |
| `name`          | string         | الطول `1-50`                                   | اسم العرض بعد التحديث                                                                                                       |
| `limitAmount`   | number \| null | الحد الأدنى `0`، الحد الأقصى للإدخال `1000000` | `null` = غير محدود، `0` = حصة صفرية. تُطبّع القيم الموجبة إلى حد مخزن لا يمكن أن يتجاوز ما يعادل `100000` دولارًا أمريكيًا. |
| `limitCurrency` | تعداد          | افتراضي `USD`                                  | USD فقط. إرسال `CNY` يُرجع `400 currency_retired`.                                                                          |
| `models`        | string\[]      | -                                              | قائمة النماذج المنطقية المسموح بها بعد التحديث                                                                              |
| `expiresAt`     | string \| null | تاريخ ووقت RFC3339                             | `null` يزيل وقت الانتهاء                                                                                                    |

## ملاحظات

* لا يدعم Management API v1 الحذف النهائي عمدًا.
* تُعامل الحالة `revoked` عادةً كحالة نهائية للاستخدام التشغيلي العادي؛ وإذا احتجت إلى مفتاح جديد، فأنشئ مفتاحًا جديدًا بدلًا من توقع وجود مسار لاحق لفك الإلغاء.

## مثال

<RequestExample>
  ```bash cURL theme={null}
  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
    }'
  ```
</RequestExample>

## الطلب / الاستجابة

استخدم لوحة OpenAPI التفاعلية أعلاه للاطلاع على المخطط الدقيق وحقول الاستجابة.

## Response example

<ResponseExample>
  ```json 200 OK theme={null}
  {
    "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"
  }
  ```
</ResponseExample>

## Important fields

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