Skip to main content

API Key Oluştur

Yeni API anahtarı oluşturur.

Endpoint

POST /api/v1/api-keys

Authentication

Bu endpoint authentication gerektirir.

Header: Authorization: Bearer \{token\}

Permission

  • api.keys.create - Tüm API anahtarlarını oluşturma
  • api.keys.create.own - Sadece kendi API anahtarını oluşturma

Request

Headers

HeaderDeğerZorunlu
AuthorizationBearer \{token\}Evet
Content-Typeapplication/jsonEvet

Request Body

ParametreTipZorunluAçıklama
namestringEvetAPI key adı
expires_atdatetimeHayırSon kullanma tarihi
permissionsarrayHayırİzin listesi
metadataobjectHayırEk metadata bilgileri (JSON)
is_activebooleanHayırAktif durumu (varsayılan: true)

Example Request

{
"name": "Production API Key",
"expires_at": "2026-12-31T23:59:59.000000Z",
"permissions": ["read", "write"],
"metadata": {
"environment": "production"
}
}

Response

Success Response (201 Created)

{
"api_key": {
"id": 1,
"uuid": "550e8400-e29b-41d4-a716-446655440000",
"name": "Production API Key",
"key_prefix": "cc_live_",
"expires_at": "2026-12-31T23:59:59.000000Z",
"is_active": true,
"user_id": 1,
"user": {
"id": 1,
"email": "user@example.com"
},
"created_at": "2025-11-20T12:00:00.000000Z"
},
"plain_key": "cc_live_abc123def456ghi789jkl012mno345pqr678stu901vwx234yz"
}

Error Responses

403 Forbidden

{
"message": "Forbidden"
}

422 Unprocessable Entity

{
"message": "Validation failed",
"errors": {
"name": ["The name field is required."]
}
}

Code Examples

cURL

curl -X POST https://api.example.com/api/v1/api-keys \
-H "Authorization: Bearer \{token\}" \
-H "Content-Type: application/json" \
-d '{
"name": "Production API Key",
"expires_at": "2026-12-31T23:59:59.000000Z"
}'

Notes

  • .own permission'ı olan kullanıcılar için user_id otomatik olarak atanır
  • is_active değeri belirtilmemişse varsayılan olarak true kullanılır
  • ÖNEMLİ: plain_key sadece oluşturulduğunda bir kez döner, sonra gösterilmez
  • API key hash'lenerek saklanır, tam key sadece oluşturulduğunda gösterilir
  • Key prefix gösterilir, tam key güvenlik nedeniyle saklanmaz