Birden fazla AI API anahtarını tek bir endpoint üzerinden yönetin
Bu API, OpenAI API formatıyla tam uyumlu bir gateway sistemidir. Arkada birden fazla AI sağlayıcısının (Google Gemini, OpenAI, Anthropic vb.) API anahtarlarını havuzlar ve akıllı yük dengeleme ile failover sağlar.
https://api.pixellab.com.tr/api/v1
/v1 prefix'i ile başlar.
OpenAI SDK kullanıyorsanız base_url olarak https://api.pixellab.com.tr/api/v1 ayarlayın.
API'ye erişmek için size verilen proje API anahtarını kullanmanız gerekir. API anahtarı iki şekilde gönderilebilir:
Authorization: Bearer pk_live_your_api_key_here
X-API-Key: pk_live_your_api_key_here
GET /v1/models?api_key=pk_live_your_api_key_here
| Prefix | Ortam | Açıklama |
|---|---|---|
pk_live_ |
Production | Canlı ortam için, gerçek API çağrıları yapar |
pk_test_ |
Test | Test ortamı için, mock yanıtlar döner |
Sohbet tamamlama endpoint'i, mesaj listesi alır ve AI modelinden yanıt üretir. OpenAI'nin Chat Completions API'si ile tam uyumludur.
| Parametre | Tip | Zorunlu | Açıklama |
|---|---|---|---|
model |
string | Evet | Kullanılacak model ID'si (örn: gemini-2.0-flash) |
messages |
array | Evet | Sohbet mesajları dizisi |
stream |
boolean | Hayır | Streaming yanıt için true (varsayılan: false) |
max_tokens |
integer | Hayır | Maksimum üretilecek token sayısı |
temperature |
float | Hayır | Yaratıcılık seviyesi (0.0 - 2.0, varsayılan: 1.0) |
top_p |
float | Hayır | Nucleus sampling parametresi (0.0 - 1.0) |
Her mesaj objesi şu alanları içermelidir:
| Alan | Tip | Açıklama |
|---|---|---|
role |
string | "system", "user" veya "assistant" |
content |
string | Mesaj içeriği |
curl -X POST "https://api.pixellab.com.tr/api/v1/chat/completions" \
-H "Authorization: Bearer pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.0-flash",
"messages": [
{"role": "system", "content": "Sen yardımcı bir asistansın."},
{"role": "user", "content": "Merhaba, nasılsın?"}
],
"temperature": 0.7,
"max_tokens": 1000
}'
{
"id": "chatcmpl-abc123def456",
"object": "chat.completion",
"created": 1704056400,
"model": "gemini-2.0-flash",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "Merhaba! Ben bir yapay zeka asistanıyım, bu yüzden gerçek anlamda bir ruh halim yok. Ama size yardımcı olmaya hazırım! Size nasıl yardımcı olabilirim?"
},
"finish_reason": "stop"
}
],
"usage": {
"prompt_tokens": 25,
"completion_tokens": 42,
"total_tokens": 67
}
}
stream: true parametresi ile yanıtlar parça parça (chunk) olarak gelir.
Bu, kullanıcıya daha hızlı geri bildirim sağlar.
curl -X POST "https://api.pixellab.com.tr/api/v1/chat/completions" \
-H "Authorization: Bearer pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "gemini-2.0-flash",
"messages": [{"role": "user", "content": "Kısa bir hikaye yaz"}],
"stream": true
}'
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":"Bir"},"index":0}]}
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":" zamanlar"},"index":0}]}
data: {"id":"chatcmpl-xxx","choices":[{"delta":{"content":" bir"},"index":0}]}
data: [DONE]
Projenizin erişebildiği modellerin listesini döner. Her proje farklı modellere erişim iznine sahip olabilir.
curl -X GET "https://api.pixellab.com.tr/api/v1/models" \
-H "Authorization: Bearer pk_live_your_api_key"
{
"object": "list",
"data": [
{
"id": "gemini-2.5-flash",
"object": "model",
"created": 1704056400,
"owned_by": "google ai studio",
"permission": [],
"root": "gemini-2.5-flash",
"parent": null
},
{
"id": "gemini-2.0-flash",
"object": "model",
"created": 1704056400,
"owned_by": "google ai studio",
"permission": [],
"root": "gemini-2.0-flash",
"parent": null
}
]
}
Metin embedding'leri oluşturur. Semantik arama, benzerlik analizi ve RAG (Retrieval-Augmented Generation) sistemleri için kullanılır.
| Parametre | Tip | Zorunlu | Açıklama |
|---|---|---|---|
model |
string | Evet | Embedding modeli (örn: text-embedding-004) |
input |
string | array | Evet | Embed edilecek metin veya metin dizisi |
curl -X POST "https://api.pixellab.com.tr/api/v1/embeddings" \
-H "Authorization: Bearer pk_live_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"model": "text-embedding-004",
"input": "Merhaba dünya, bu bir test metnidir."
}'
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [0.0023, -0.0091, 0.0152, ... ]
}
],
"model": "text-embedding-004",
"usage": {
"prompt_tokens": 8,
"total_tokens": 8
}
}
API hatalarında aşağıdaki HTTP durum kodları ve hata formatı döner:
{
"error": {
"message": "Hata açıklaması",
"type": "error_type",
"code": 400
}
}
| Kod | Tip | Açıklama |
|---|---|---|
| 400 | invalid_request_error | Geçersiz istek parametreleri |
| 401 | authentication_error | Geçersiz veya eksik API anahtarı |
| 403 | permission_error | Model erişim izni yok |
| 404 | not_found_error | Endpoint veya kaynak bulunamadı |
| 429 | rate_limit_error | Rate limit aşıldı, lütfen bekleyin |
| 500 | api_error | Sunucu hatası |
| 503 | service_unavailable | Servis geçici olarak kullanılamıyor |
Bu API, OpenAI SDK'ları ile tam uyumludur. Sadece base URL'i değiştirerek mevcut kodunuzu kullanabilirsiniz.
from openai import OpenAI
# Client oluştur - sadece base_url ve api_key değiştirin
client = OpenAI(
base_url="https://api.pixellab.com.tr/api/v1",
api_key="pk_live_your_api_key"
)
# Normal OpenAI kullanımı gibi çağrı yapın
response = client.chat.completions.create(
model="gemini-2.0-flash",
messages=[
{"role": "system", "content": "Sen yardımcı bir asistansın."},
{"role": "user", "content": "Python'da liste nasıl oluşturulur?"}
],
temperature=0.7,
max_tokens=500
)
print(response.choices[0].message.content)
stream = client.chat.completions.create(
model="gemini-2.0-flash",
messages=[{"role": "user", "content": "Kısa bir hikaye yaz"}],
stream=True
)
for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="", flush=True)
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://api.pixellab.com.tr/api/v1',
apiKey: 'pk_live_your_api_key'
});
async function chat() {
const response = await client.chat.completions.create({
model: 'gemini-2.0-flash',
messages: [
{ role: 'user', content: 'Merhaba, bana yardım eder misin?' }
]
});
console.log(response.choices[0].message.content);
}
chat();
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => 'https://api.pixellab.com.tr/api/v1/chat/completions',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer pk_live_your_api_key',
'Content-Type: application/json'
],
CURLOPT_POSTFIELDS => json_encode([
'model' => 'gemini-2.0-flash',
'messages' => [
['role' => 'user', 'content' => 'Merhaba!']
]
])
]);
$response = curl_exec($ch);
$data = json_decode($response, true);
echo $data['choices'][0]['message']['content'];
max_tokens parametresini makul tutun