Alesta WEB

ChatGPT API kullanırken "Rate limit exceeded" hatası mı alıyorsunuz (getting rate limit exceeded error)? Alesta Web olarak 2025'te en güncel çözümleri, best practice'leri ve API limitlerini optimize etme yöntemlerini (optimization methods) kapsamlı şekilde anlatıyoruz. OpenAI API rate limiting konusunda bilmeniz gereken her şey bu rehberde!
Rate Limit Nedir? (What is Rate Limiting?)
Alesta Web açıklaması: Rate limiting, OpenAI'ın API sunucularını korumak için uyguladığı kullanım sınırlamalarıdır (usage restrictions to protect servers). Belirli bir zaman diliminde yapabileceğiniz istek sayısını (request count) ve kullanabileceğiniz token miktarını (token amount) kısıtlar.
? Rate Limit Türleri / Rate Limit Types
| Limit Türü / Type | Açıklama / Description | Örnek / Example |
|---|---|---|
| RPM (Requests per Minute) | Dakikada yapılabilecek istek sayısı | 500 RPM (Free tier) |
| RPD (Requests per Day) | Günlük toplam istek sayısı | 10,000 RPD |
| TPM (Tokens per Minute) | Dakikada kullanılabilecek token | 40,000 TPM |
| TPD (Tokens per Day) | Günlük toplam token kullanımı | 2,000,000 TPD |
Token hesaplaması: Yaklaşık olarak 1 token = 4 karakter (1 token ≈ 4 characters). "Merhaba dünya" ≈ 3 token. Türkçe metinler genellikle İngilizce'den daha fazla token tüketir (Turkish texts consume more tokens than English).
Hata Tipleri ve Anlamları (Error Types and Meanings)
Alesta Web test sonuçları: Karşılaşabileceğiniz farklı rate limit hataları (different rate limit errors):
❌ 429 Rate Limit Exceeded Hataları
// Tip 1: RPM Aşımı (RPM Exceeded)
{
"error": {
"message": "Rate limit reached for requests",
"type": "requests",
"param": null,
"code": "rate_limit_exceeded"
}
}
// Tip 2: TPM Aşımı (TPM Exceeded)
{
"error": {
"message": "Rate limit reached for tokens per minute",
"type": "tokens",
"param": null,
"code": "rate_limit_exceeded"
}
}
// Tip 3: Günlük Limit Aşımı (Daily Limit Exceeded)
{
"error": {
"message": "You exceeded your current quota",
"type": "insufficient_quota",
"param": null,
"code": "insufficient_quota"
}
}rate_limit_exceeded geçicidir (temporary) - birkaç saniye/dakika bekleyin. insufficient_quota kredi bitmiş demektir (credits depleted) - ödeme yapmanız gerekir!
? Response Header'larını Kontrol Edin
# curl ile test (check with curl):
curl https://api.openai.com/v1/chat/completions \
-H "Authorization: Bearer YOUR_API_KEY" \
-I
# Önemli header'lar:
x-ratelimit-limit-requests: 500
x-ratelimit-remaining-requests: 342
x-ratelimit-reset-requests: 12s
x-ratelimit-limit-tokens: 40000
x-ratelimit-remaining-tokens: 284502025 OpenAI API Limitleri (2025 OpenAI API Limits)
Alesta Web güncel veri analizi (current data analysis) - Aralık 2025:
| Tier | GPT-4 RPM | GPT-4 TPM | GPT-3.5 RPM | Gereksinim / Requirement |
|---|---|---|---|---|
| Free (Tier 0) | 3 RPM | 40K TPM | 500 RPM | Telefon doğrulama (phone verification) |
| Tier 1 | 500 RPM | 10M TPM | 3,500 RPM | $5+ ödeme (payment) |
| Tier 2 | 5,000 RPM | 40M TPM | 3,500 RPM | $50+ ödeme + 7 gün (7 days) |
| Tier 3 | 10,000 RPM | 80M TPM | 3,500 RPM | $100+ ödeme + 7 gün |
| Tier 4 | 10,000 RPM | 300M TPM | 10,000 RPM | $250+ ödeme + 14 gün |
| Tier 5 | 10,000 RPM | 300M TPM | 10,000 RPM | $1,000+ ödeme + 30+ gün |
Free tier ile GPT-4'ü test edebilirsiniz (can test GPT-4), ama production'da Tier 1+ gerekli (Tier 1+ required for production). Sadece $5 yükleyerek 500 RPM'e çıkıyorsunuz - büyük fark (big difference)!
o1-preview: 500 RPM (Tier 5) | o1-mini: 1,000 RPM (Tier 5)
Bu modellere erişim için en az Tier 5 gereklidir (Tier 5 required for these models).
Hızlı Çözümler (Quick Solutions)
Alesta Web önerilen yaklaşımlar (recommended approaches):
✅ Çözüm 1: Exponential Backoff (Üstel Geri Çekilme)
429 hatası aldığınızda bekleyin ve tekrar deneyin (wait and retry):
import time
import openai
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY")
def api_call_with_backoff(prompt, max_retries=5):
"""Exponential backoff ile API çağrısı"""
for attempt in range(max_retries):
try:
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}]
)
return response
except openai.RateLimitError as e:
if attempt == max_retries - 1:
raise e
# Exponential backoff: 1s, 2s, 4s, 8s, 16s
wait_time = 2 ** attempt
print(f"Rate limit! {wait_time}s bekleniyor...")
time.sleep(wait_time)
# Kullanım:
result = api_call_with_backoff("Merhaba, nasılsın?")
print(result.choices[0].message.content)✅ Çözüm 2: Request Queue (İstek Kuyruğu)
İstekleri kuyruğa alıp kontrollü şekilde gönder (queue requests):
import asyncio
from asyncio import Semaphore
# RPM limit: 500 -> Saniyede max 8 istek (500/60 ≈ 8)
MAX_CONCURRENT_REQUESTS = 8
semaphore = Semaphore(MAX_CONCURRENT_REQUESTS)
async def rate_limited_request(prompt):
"""Rate limit'e uygun async istek"""
async with semaphore:
response = await client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt}]
)
return response
async def process_batch(prompts):
"""Toplu işlem"""
tasks = [rate_limited_request(p) for p in prompts]
results = await asyncio.gather(*tasks)
return results
# Kullanım:
prompts = ["Soru 1", "Soru 2", "Soru 3", ...]
results = asyncio.run(process_batch(prompts))✅ Çözüm 3: Token Optimizasyonu
Gereksiz token kullanımını azaltın (reduce unnecessary tokens):
import tiktoken
def count_tokens(text, model="gpt-4"):
"""Token sayısını hesapla"""
encoding = tiktoken.encoding_for_model(model)
return len(encoding.encode(text))
# Prompt'u optimize et
original = "Lütfen bu metni çok detaylı şekilde analiz edip..."
optimized = "Bu metni analiz et: ..."
print(f"Original: {count_tokens(original)} tokens")
print(f"Optimized: {count_tokens(optimized)} tokens")
# max_tokens ile limit koy
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": prompt}],
max_tokens=500 # Cevap maksimum 500 token
)✅ Çözüm 4: Caching (Önbellekleme)
from functools import lru_cache
import hashlib
# Aynı prompt'lar için cache kullan
@lru_cache(maxsize=1000)
def cached_api_call(prompt_hash):
"""Önbellekli API çağrısı"""
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": prompt_hash}]
)
return response.choices[0].message.content
def get_response(prompt):
# Prompt hash'le (aynı prompt = aynı cache)
prompt_hash = hashlib.md5(prompt.encode()).hexdigest()
return cached_api_call(prompt_hash)Kod Örnekleri: Python & Node.js (Code Examples)
Alesta Web production-ready kod örnekleri (production-ready code samples):
? Python: Tam Çözüm (Complete Solution)
"""
Alesta Web - ChatGPT API Rate Limit Handler
Python production-ready implementation
"""
import openai
from openai import OpenAI
import time
from tenacity import retry, stop_after_attempt, wait_exponential
client = OpenAI(api_key="YOUR_API_KEY")
@retry(
stop=stop_after_attempt(5),
wait=wait_exponential(multiplier=1, min=1, max=60)
)
def robust_api_call(
prompt: str,
model: str = "gpt-3.5-turbo",
max_tokens: int = 1000
):
"""
Rate limit ve diğer hataları handle eden API çağrısı
Args:
prompt: Kullanıcı sorusu
model: Model adı
max_tokens: Maksimum cevap uzunluğu
Returns:
API yanıtı
"""
try:
response = client.chat.completions.create(
model=model,
messages=[
{"role": "system", "content": "Sen yardımcı bir asistansın."},
{"role": "user", "content": prompt}
],
max_tokens=max_tokens,
temperature=0.7
)
# Token kullanımını logla
usage = response.usage
print(f"✅ Token: {usage.total_tokens} "
f"(prompt: {usage.prompt_tokens}, "
f"completion: {usage.completion_tokens})")
return response.choices[0].message.content
except openai.RateLimitError as e:
print(f"⚠️ Rate limit! Retry ediliyor...")
raise # tenacity retry yapacak
except openai.APIError as e:
print(f"❌ API Error: {e}")
raise
except Exception as e:
print(f"❌ Beklenmeyen hata: {e}")
raise
# Kullanım:
if __name__ == "__main__":
result = robust_api_call("Python'da liste comprehension nedir?")
print(result)? Node.js: Rate Limiter (Bottleneck)
/**
* Alesta Web - ChatGPT API Rate Limit Handler
* Node.js production implementation with Bottleneck
*/
const OpenAI = require('openai');
const Bottleneck = require('bottleneck');
const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY
});
// Rate limiter yapılandırması
// 500 RPM = dakikada 500 istek = saniyede ~8 istek
const limiter = new Bottleneck({
minTime: 125, // İstekler arası min 125ms (1000/8)
maxConcurrent: 5, // Aynı anda max 5 istek
reservoir: 500, // Dakikada 500 istek
reservoirRefreshAmount: 500,
reservoirRefreshInterval: 60 * 1000 // 60 saniye
});
/**
* Rate limit'li API çağrısı
*/
const rateLimitedCall = limiter.wrap(async (prompt, model = 'gpt-3.5-turbo') => {
try {
const response = await openai.chat.completions.create({
model: model,
messages: [
{ role: 'system', content: 'Sen yardımcı bir asistansın.' },
{ role: 'user', content: prompt }
],
max_tokens: 1000
});
console.log(`✅ Token: ${response.usage.total_tokens}`);
return response.choices[0].message.content;
} catch (error) {
if (error.status === 429) {
console.log('⚠️ Rate limit! Bekleyip retry edilecek...');
// Bottleneck otomatik retry yapacak
throw error;
}
throw error;
}
});
// Kullanım:
(async () => {
const result = await rateLimitedCall('Node.js async/await nedir?');
console.log(result);
})();
// Toplu işlem örneği:
async function processBatch(prompts) {
const promises = prompts.map(p => rateLimitedCall(p));
return await Promise.all(promises);
}Python için tenacity kütüphanesi, Node.js için bottleneck kütüphanesi production'da kanıtlanmış çözümlerdir (proven solutions). NPM/pip ile yükleyebilirsiniz.
Best Practices (En İyi Uygulamalar)
Alesta Web production tecrübesi (production experience):
✅ 1. Header'ları Takip Edin (Monitor Headers)
def check_rate_limits(response_headers):
"""Response header'larından limit bilgisi al"""
remaining_requests = int(response_headers.get(
'x-ratelimit-remaining-requests', 0
))
remaining_tokens = int(response_headers.get(
'x-ratelimit-remaining-tokens', 0
))
print(f"Kalan istek: {remaining_requests}")
print(f"Kalan token: {remaining_tokens}")
# Limit dolmak üzereyse uyar
if remaining_requests < 10:
print("⚠️ Dikkat: İstek limiti dolmak üzere!")
if remaining_tokens < 1000:
print("⚠️ Dikkat: Token limiti dolmak üzere!")✅ 2. Batch Processing (Toplu İşlem)
Birden fazla isteği gruplayın (group multiple requests):
- ✅ Tek seferde 20 kullanıcı sorusu varsa, batch'leyip sırayla gönderin
- ✅ Her 100ms'de bir istek gönderin (stay under limit)
- ❌ Hepsini aynı anda göndermeyin (don't send all at once)
✅ 3. Model Seçimi (Model Selection)
| Kullanım / Use Case | Önerilen Model / Recommended | Sebep / Reason |
|---|---|---|
| Basit soru-cevap (simple Q&A) | gpt-3.5-turbo | Daha hızlı, ucuz, yüksek RPM |
| Kod oluşturma (code generation) | gpt-4-turbo | Daha kaliteli kod |
| Karmaşık reasoning | gpt-4 veya o1-preview | En iyi anlama yeteneği |
| Çeviri (translation) | gpt-3.5-turbo | Yeterince iyi + ekonomik |
✅ 4. Streaming Kullanın (Use Streaming)
Uzun cevaplar için stream mode daha iyi UX sağlar (better UX for long responses):
stream = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Yapay zeka nedir?"}],
stream=True # Streaming aktif
)
for chunk in stream:
if chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end='')- ❌ Her istek için yeni client oluşturmak (creating new client per request)
- ❌ Error handling yapmamak (no error handling)
- ❌ Token sayısını kontrol etmemek (not checking token count)
- ❌ Retry logic olmadan production'a çıkmak (no retry logic in production)
Tier Upgrade Rehberi (Tier Upgrade Guide)
Alesta Web adım adım tier yükseltme (step-by-step tier upgrade):
? Tier Atlama Süreci (Tier Progression)
1️⃣ Hesap Oluştur (Create Account):
- https://platform.openai.com/signup
- E-posta ve telefon doğrula (verify email & phone)
2️⃣ Ödeme Yöntemi Ekle (Add Payment Method):
- Settings > Billing > Payment methods
- Kredi kartı veya PayPal (credit card or PayPal)
3️⃣ Kredi Yükle (Add Credits):
Free → Tier 1: Minimum $5 yükle
Tier 1 → Tier 2: Toplam $50+ harcama + 7 gün bekle
Tier 2 → Tier 3: Toplam $100+ + 7 gün
Tier 3 → Tier 4: Toplam $250+ + 14 gün
Tier 4 → Tier 5: Toplam $1,000+ + 30+ gün
4️⃣ Kontrol Et (Check Status):
- Settings > Limits
- Güncel tier'ınızı görebilirsinizTier 1 çoğu küçük-orta proje için yeterli (sufficient for most small-medium projects). $5 ile 500 RPM + 10M TPM alıyorsunuz. Production'da günlük 100-1000 kullanıcınız varsa Tier 1 yeterli.
Tier 3+ enterprise uygulamalar için (for enterprise apps) - 10K+ kullanıcı, yüksek trafik.
? Maliyet Hesaplama (Cost Calculation)
GPT-3.5-turbo (Aralık 2025):
Input: $0.0005 / 1K token
Output: $0.0015 / 1K token
GPT-4-turbo (Aralık 2025):
Input: $0.01 / 1K token
Output: $0.03 / 1K token
Örnek (Example):
1000 kullanıcı, her biri 500 token soru + 1000 token cevap
GPT-3.5: (500*0.0005 + 1000*0.0015) * 1000 = $1,750
GPT-4: (500*0.01 + 1000*0.03) * 1000 = $35,000Alesta Web tavsiyesi: Basit işlemler için GPT-3.5, karmaşık işlemler için GPT-4 kullanın (use GPT-3.5 for simple, GPT-4 for complex). Hibrit yaklaşım %70 maliyet tasarrufu sağlar (hybrid approach saves 70% cost)!
Monitoring ve Tracking (Monitoring and Tracking)
Alesta Web production monitoring stratejisi (production monitoring strategy):
? Usage Tracking Kodu (Usage Tracking Code)
"""
API kullanımını logla ve analiz et
"""
import json
from datetime import datetime
from collections import defaultdict
class APIUsageTracker:
def __init__(self):
self.usage_log = []
def log_request(self, model, tokens_used, cost, success=True):
"""Her API isteğini logla"""
entry = {
'timestamp': datetime.now().isoformat(),
'model': model,
'tokens': tokens_used,
'cost': cost,
'success': success
}
self.usage_log.append(entry)
# Dosyaya kaydet
with open('api_usage.json', 'a') as f:
f.write(json.dumps(entry) + '\n')
def get_daily_stats(self):
"""Günlük istatistikler"""
today = datetime.now().date()
daily_data = defaultdict(lambda: {'requests': 0, 'tokens': 0, 'cost': 0})
for entry in self.usage_log:
entry_date = datetime.fromisoformat(entry['timestamp']).date()
if entry_date == today:
model = entry['model']
daily_data[model]['requests'] += 1
daily_data[model]['tokens'] += entry['tokens']
daily_data[model]['cost'] += entry['cost']
return daily_data
def alert_if_high_usage(self, threshold_cost=100):
"""Yüksek maliyet uyarısı"""
stats = self.get_daily_stats()
total_cost = sum(m['cost'] for m in stats.values())
if total_cost > threshold_cost:
print(f"⚠️ UYARI: Günlük maliyet ${total_cost:.2f} - "
f"threshold (${threshold_cost}) aşıldı!")
return True
return False
# Kullanım:
tracker = APIUsageTracker()
def tracked_api_call(prompt, model='gpt-3.5-turbo'):
try:
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
# Kullanımı logla
tokens = response.usage.total_tokens
cost = calculate_cost(model, tokens) # Kendi fonksiyonunuz
tracker.log_request(model, tokens, cost, success=True)
return response
except Exception as e:
tracker.log_request(model, 0, 0, success=False)
raise e
# Her gün kontrol et
tracker.alert_if_high_usage(threshold_cost=50)? Prometheus/Grafana ile Monitoring
from prometheus_client import Counter, Histogram, start_http_server
# Metrikler
api_requests_total = Counter(
'openai_api_requests_total',
'Total API requests',
['model', 'status']
)
api_tokens_used = Counter(
'openai_api_tokens_total',
'Total tokens used',
['model', 'type']
)
api_latency = Histogram(
'openai_api_latency_seconds',
'API latency',
['model']
)
# Monitored API call
def monitored_api_call(prompt, model='gpt-3.5-turbo'):
with api_latency.labels(model=model).time():
try:
response = client.chat.completions.create(
model=model,
messages=[{"role": "user", "content": prompt}]
)
# Success metriği
api_requests_total.labels(model=model, status='success').inc()
# Token metriği
api_tokens_used.labels(
model=model, type='prompt'
).inc(response.usage.prompt_tokens)
api_tokens_used.labels(
model=model, type='completion'
).inc(response.usage.completion_tokens)
return response
except Exception as e:
api_requests_total.labels(model=model, status='error').inc()
raise e
# Prometheus server başlat
start_http_server(8000) # http://localhost:8000/metricsOpenAI'ın kendi dashboard'u (platform.openai.com/usage) temel istatistikler için yeterli. Advanced analytics için kendi tracking sisteminizi kurun (build your own tracking) - Prometheus + Grafana ideal!
? Kaynaklar ve Referanslar / Sources and References
Bu makalede kullanılan kaynaklar ve ileri okuma (sources and further reading):
- OpenAI Official Documentation - Rate Limits
- OpenAI Platform - Your Rate Limits
- OpenAI Python SDK - GitHub
- OpenAI Node.js SDK - GitHub
- OpenAI Cookbook - Rate Limit Handling
- Bottleneck - Node.js Rate Limiter
- Tenacity - Python Retry Library
Alesta Web test laboratuvarı kendi production deneyimlerini eklemiştir (added own production experience).
✅ ChatGPT API Rate Limit: Sonuç (Final Summary)
Alesta Web 2025 nihai önerileri (2025 final recommendations):
- ✅ Exponential backoff uygula (implement exponential backoff)
- ✅ Rate limiter kütüphanesi kullan (Python: tenacity, Node.js: bottleneck)
- ✅ Token kullanımını optimize et (optimize token usage)
- ✅ Caching mekanizması ekle (add caching mechanism)
- ✅ Tier 1'e upgrade et ($5 yeterli / $5 is enough)
- ✅ Production'da monitoring kur (set up monitoring)
- ✅ Error handling ekle (add error handling)
- ✅ GPT-3.5 ve GPT-4'ü hibrit kullan (use GPT-3.5 & GPT-4 hybrid)
- Tier 1'e hemen geç (upgrade to Tier 1 immediately) - $5 ile 3 RPM'den 500 RPM'e çık, büyük fark!
- Retry logic mutlaka ekle (always add retry logic) - Production'da 429 hatası kaçınılmaz, hazırlıklı ol
- Token'ları optimize et (optimize tokens) - Gereksiz uzun prompt'lar maliyet ve limit kaybı
- ❌ Free tier ile production'a çıkmak (going to production with free tier)
- ❌ Rate limit olmadan infinite loop (infinite loop without rate limiting)
- ❌ Her istek için GPT-4 kullanmak (using GPT-4 for every request) - gereksiz maliyet!
Faydalı Linkler / Useful Links:
- OpenAI Platform: platform.openai.com
- API Docs: platform.openai.com/docs
- Usage Dashboard: platform.openai.com/usage
- Alesta Web: alestaweb.com
- Alesta Web API Rehberleri: API Integration Guides
Son Söz:
ChatGPT API rate limit'leri başlangıçta zorlayıcı görünebilir, ama doğru stratejiler ile kolayca yönetilebilir (can be easily managed with right strategies). Alesta Web olarak production'da test ettiğimiz bu yöntemler, binlerce kullanıcılı uygulamalarda sorunsuz çalışıyor. Sizin projenizde de başarılar dileriz!
© 2025 AlestaWeb - Tüm hakları saklıdır. / All rights reserved.

