Kullanım
API kullanım istatistiklerinizi sorgulayın: aylık istek sayısı, kredi tüketimi, en çok kullanılan endpoint’ler ve son isteklerin özeti.
Kullanım İstatistikleri
GET/v1/usage
Mevcut API anahtarının kullanım özetini döner.
Kod Örnekleri
Node.js
kullanim-ozet.js
const response = await fetch('https://api.sosyalkopru.com/v1/usage', {
headers: { 'Authorization': `Bearer ${process.env.SOSYALKOPRU_API_KEY}` },
})
const { data } = await response.json()
console.log('=== Hesap ===')
console.log(`Plan : ${data.apiKey.planTier}`)
console.log(`Kredi : ${data.apiKey.creditBalance.toLocaleString('tr-TR')}`)
console.log(`Toplam : ${data.apiKey.totalRequests.toLocaleString('tr-TR')} istek`)
console.log('\n=== Bu Ay ===')
console.log(`İstekler : ${data.currentMonth.requests.toLocaleString('tr-TR')}`)
console.log(`Kredi har.: ${data.currentMonth.creditsUsed.toLocaleString('tr-TR')}`)
// Kredi uyarısı
if (data.apiKey.creditBalance < 100) {
console.warn('\n⚠️ Kredi bakiyeniz düşük! Lütfen yükleyin.')
}
console.log('\n=== En Çok Kullanılan Endpoint\'ler ===')
data.topEndpoints.forEach(e => {
console.log(` ${e.requests.toString().padStart(6)} istek ${e.endpoint}`)
})
console.log('\n=== Son 10 İstek ===')
data.recentRequests.forEach(r => {
const ok = r.statusCode < 400 ? '✓' : '✗'
console.log(`${ok} ${r.method} ${r.endpoint} [${r.statusCode}] ${r.durationMs}ms`)
})Başarılı Yanıt
{
"success": true,
"data": {
"apiKey": {
"id": "key_01HZGK9P3QABC",
"name": "Üretim Anahtarı",
"planTier": "growth",
"creditBalance": 842,
"totalRequests": 12480,
"expiresAt": null,
"lastUsedAt": "2025-06-12T09:30:00.000Z"
},
"currentMonth": {
"requests": 1240,
"creditsUsed": 158,
"periodStart": "2025-06-01T00:00:00.000Z",
"periodEnd": "2025-06-30T00:00:00.000Z"
},
"topEndpoints": [
{ "endpoint": "/v1/posts", "requests": 420 },
{ "endpoint": "/v1/analytics/overview", "requests": 218 },
{ "endpoint": "/v1/accounts", "requests": 186 },
{ "endpoint": "/v1/media/upload", "requests": 124 },
{ "endpoint": "/v1/webhooks", "requests": 97 }
],
"recentRequests": [
{
"endpoint": "/v1/posts",
"method": "POST",
"statusCode": 201,
"creditsUsed": 2,
"durationMs": 142,
"timestamp": "2025-06-12T09:30:00.000Z"
},
{
"endpoint": "/v1/analytics/overview",
"method": "GET",
"statusCode": 200,
"creditsUsed": 1,
"durationMs": 87,
"timestamp": "2025-06-12T09:28:00.000Z"
}
]
},
"meta": { "requestId": "req_01XYZ", "timestamp": "...", "version": "1" }
}Yanıt Alanları
| Alan | Açıklama |
|---|---|
apiKey.planTier | starter growth agency_pro |
apiKey.creditBalance | Kalan kredi miktarı |
apiKey.totalRequests | API anahtarının ömür boyu toplam istek sayısı |
currentMonth.requests | Bu ayki toplam istek sayısı (tüm durum kodları) |
currentMonth.creditsUsed | Bu ayki başarılı isteklerde harcanan kredi |
topEndpoints | Bu ay en çok kullanılan 10 endpoint (istek sayısına göre sıralı) |
recentRequests | Son 10 istek (en yeniden eskiye) |
Kredi Maliyetleri
| İşlem | Kredi |
|---|---|
GET /posts, GET /accounts vb. okuma | 1 |
POST /posts (gönderi oluşturma) | 2 |
POST /media/upload | 2 |
GET /analytics/* | 1 |
POST /posts/bulk | 1 + gönderi başına 1 |
GET /usage, GET /me | 0 |
Last updated on