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şturmaapi.keys.create.own- Sadece kendi API anahtarını oluşturma
Request
Headers
| Header | Değer | Zorunlu |
|---|---|---|
Authorization | Bearer \{token\} | Evet |
Content-Type | application/json | Evet |
Request Body
| Parametre | Tip | Zorunlu | Açıklama |
|---|---|---|---|
name | string | Evet | API key adı |
expires_at | datetime | Hayır | Son kullanma tarihi |
permissions | array | Hayır | İzin listesi |
metadata | object | Hayır | Ek metadata bilgileri (JSON) |
is_active | boolean | Hayır | Aktif 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
.ownpermission'ı olan kullanıcılar içinuser_idotomatik olarak atanıris_activedeğeri belirtilmemişse varsayılan olaraktruekullanılır- ÖNEMLİ:
plain_keysadece 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
Related Endpoints
- API Key Listesi - Tüm API anahtarlarını listele
- API Key Detayı - API key detayını getir