Yapay Zeka Koşuları
Yapay zeka özellikleri önceden tanımlanmış yeteneklerdir (ör. özetleme, analiz, koçluk). Her çağrı, yürütmeyi adım adım izleyen bir çalıştırma oluşturur.
Sözleşme güncellemesi (2026-04): POST isteğinin gövdesi, canlı API ile eşleşecek şekilde düzeltildi.
inputnesnesi,agentIdveworkspaceIdalanları kabul edilmez. Bunun yerinemessagesdizisini kullanın.
Yanıt örneklerindeki kimlikler sentetik UUID değerleridir. İsteklerinizin döndürdüğü kimlikleri kullanın.
Orkestrasyon Çözüm Yolunu Çalıştır
- Mevcut özellik anahtarlarını keşfetmek için kataloğu (
GET /ai/features) listeleyin. - Bir çalıştırmayı (
POST /ai/features/:featureKey/runs), kullanıcı istemini içeren birmessagesdizisiyle oluşturun. - Çalıştırma durumunu
GET /ai/runs/:runIdveyaGET /ai/runs/:runId/stepsyoluyla izleyin ve son yanıtı ve tamamlanma olayınıGET /ai/runs/:runId/streamaracılığıyla alın. - Bir çalıştırma durduğunda iptal edin (
POST /ai/runs/:runId/cancel) veya yeniden deneyin (POST /ai/runs/:runId/retry) ve ardından çalıştırma tamamlandığında sonresultalanını yakalayın.
const orchestrateFeature = async () => {
const featureRes = await fetch(`https://api.chainabit.com/api/v1/ai/features`, {
headers: { Authorization: `Bearer ${TOKEN}` },
});
if (!featureRes.ok) throw new Error(`Feature catalog request failed: ${featureRes.status}`);
const feature = (await featureRes.json()).find(
(f) => f.key === "ai.chat.multi_agent" && f.isActive && f.isVisibleOnPlan
);
if (!feature) throw new Error("The selected AI feature is unavailable on this account");
const idempotencyKey = crypto.randomUUID(); // Reuse this key only for retries of this request.
const runRes = await fetch(
`https://api.chainabit.com/api/v1/ai/features/${feature.key}/runs`,
{
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({
messages: [
{ role: "user", content: "Help me maintain my daily vocabulary completion history" }
],
}),
}
);
if (!runRes.ok) throw new Error(`Run creation failed: ${runRes.status}`);
const { runId } = await runRes.json();
if (!runId) throw new Error("Run ID missing from response");
const streamController = new AbortController(); // Call abort() to stop viewing.
const streamRes = await fetch(`https://api.chainabit.com/api/v1/ai/runs/${runId}/stream`, {
signal: AbortSignal.any([streamController.signal, AbortSignal.timeout(60_000)]),
headers: { Authorization: `Bearer ${TOKEN}`, Accept: "text/event-stream" },
});
if (!streamRes.ok || !streamRes.body) throw new Error("Could not open run stream");
const reader = streamRes.body.getReader();
const decoder = new TextDecoder();
try {
while (true) {
const { done, value } = await reader.read();
if (done) break;
console.log(decoder.decode(value, { stream: true })); // raw SSE frames
}
} finally {
try { await reader.cancel(); } finally { reader.releaseLock(); }
}
};Uç noktalar
| Yöntem | Yol | Açıklama | Kimlik doğrulama |
|---|---|---|---|
| GET | /ai/features | AI özellik kataloğunu listele | JWT + yetki |
| POST | /ai/features/:featureKey/runs | Bir özellik için çalıştırma oluştur | JWT + yetki |
| GET | /ai/runs | Çalıştırmaları listele (filtrelenebilir) | JWT + yetki |
| GET | /ai/runs/:runId | Bir çalıştırmayı getir | JWT + yetki |
| GET | /ai/runs/:runId/steps | Bir çalıştırmanın adımlarını listele | JWT + yetki |
| GET | /ai/runs/:runId/stream | Bir çalıştırma için SSE akışı | JWT + yetki |
| POST | /ai/runs/:runId/cancel | Devam eden bir çalıştırmayı iptal et | JWT + yetki |
| POST | /ai/runs/:runId/retry | Mevcut özellik çalıştırmasından yeni çalıştırma oluştur | JWT + yetki |
| POST | /ai/runs/:runId/resume | Kurtarılabilir kesintili bir çalıştırmayı sürdür | JWT + yetki |
GET /ai/features
Katalogda mevcut tüm AI özelliklerini listeleyin.
Kimlik Doğrulama: JWT Taşıyıcı jetonu gereklidir.
İstek
Yol veya sorgu parametresi yok. İstek gövdesi yok.
Cevap
Yanıt Örneği
[
{
"key": "ai.chat.multi_agent",
"aliases": [],
"isActive": true,
"isVisibleOnPlan": true
}
]Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
key | string | Özellik kimliği |
aliases | string[] | Takma adlar; mevcut katalog boş bir liste döndürür |
isActive | boolean | Özelliğin etkin olup olmadığı |
isVisibleOnPlan | boolean | Çağıranın planının özelliği sunup sunmadığı |
Kod Örnekleri
const res = await fetch(`https://api.chainabit.com/api/v1/ai/features`, {
headers: { Authorization: `Bearer ${TOKEN}` },
});
const features = await res.json();import requests
res = requests.get(
f"{BASE_URL}/ai/features",
headers={"Authorization": f"Bearer {TOKEN}"},
)
features = res.json()POST /ai/runs/:runId/resume
Kurtarılabilir bir durumda duran çalıştırmayı sürdürür. İstek gövdesi yoktur.
Başarılı istek 200 OK ile çalıştırma id değerini, yeni status değerini ve replayed boolean alanını döndürür. Çalıştırma çağıranın izin verilen kapsamı dışındaysa API 403, çalıştırma kurtarılabilir durumda değilse 409 conversation_run_not_resumable döndürür.
POST /ai/features/:featureKey/runs
Belirtilen AI özelliği için yeni bir çalıştırma oluşturun. Aktif bir abonelik veya uygun satın alınmış krediler ile özelliğe erişim gerekir.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
Finansman gereklidir. Yetki ve kullanılabilir krediler tek başına çıkarım işlemini yetkilendirmez. Finansman ve azami maliyet doğrulanana kadar ücret doğuran işlemler duraklatılır. Kabul edilen eşzamansız çalıştırma daha sonra
faileddurumunda sonlanabilir; başarı bildirmeden önce son durumunu kontrol edin. İsteği tekrarlamak finansman nedeniyle duraklatılan işlemi çözmez.
İstek
| Alan | Tür | Zorunlu | Kısıtlamalar | Açıklama |
|---|---|---|---|---|
messages | array | Evet | 1–50 öğe | Gönderilecek konuşma mesajları |
messages[].role | string | Evet | "user" | Mesajı yazanın rolü |
messages[].content | string | Evet | Boş olamaz | Mesaj içeriği |
temperature | number | Hayır | 0–2 | Örnekleme sıcaklığı |
maxOutputTokens | number | Hayır | 1–200,000 | Yanıttaki azami jeton sayısı |
provider | string | Hayır | Sağlayıcı anahtarı | Planın erişimine bağlı sağlayıcı seçimi |
effortMode | string | Hayır | basic, thinking, pro | Model seçimi çaba düzeyi |
Her mantıksal oluşturma isteği için benzersiz bir Idempotency-Key başlığı gönderin. Aynı HTTP isteğini yeniden gönderirken bu anahtarı tekrar kullanın. Bu başlık zorunludur; gövdedeki bir alan onun yerine geçmez. Başlık yoksa 428 missing_idempotency_key döner.
Cevap
Yanıt Örneği
{
"requestId": "00000000-0000-4000-8000-000000000002",
"runId": "00000000-0000-4000-8000-000000000001",
"result": { "finishReason": "running", "text": "" }
}Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
requestId | string | İstek kimliği |
runId | string (isteğe bağlı) | Çalıştırma oluşturulduysa yeni çalıştırmanın kimliği |
result | object | Yürütme sonucu; kabul edilen eşzamansız çalıştırmada finishReason: "running" olabilir |
Kod Örnekleri
const idempotencyKey = crypto.randomUUID(); // Keep this key when retrying the same request.
const res = await fetch(`https://api.chainabit.com/api/v1/ai/features/ai.chat.multi_agent/runs`, {
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({
messages: [
{
role: "user",
content: "I have been struggling to maintain my daily vocabulary practice completion history",
},
],
}),
});
const { requestId, runId, result } = await res.json();import requests
import uuid
idempotency_key = str(uuid.uuid4()) # Keep for retries of this request.
res = requests.post(
f"{BASE_URL}/ai/features/ai.chat.multi_agent/runs",
headers={
"Authorization": f"Bearer {TOKEN}",
"Content-Type": "application/json",
"Idempotency-Key": idempotency_key,
},
json={
"messages": [
{
"role": "user",
"content": "I have been struggling to maintain my daily vocabulary practice completion history",
}
]
},
)
result = res.json() # requestId, optional runId, resultGET /ai/runs
İsteğe bağlı filtrelerle tüm çalıştırmaları listeleyin.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
| Parametre | Tür | Zorunlu | Açıklama |
|---|---|---|---|
agentId | string | Hayır | Ajana göre filtrele |
workspaceId | string | Hayır | Çalışma alanına göre filtrele |
featureKey | string | Hayır | Özelliğe göre filtrele |
status | string | Hayır | Duruma göre filtrele: queued, running, completed, failed, cancelled |
limit | number | Hayır | Sayfa başına öğe |
offset | number | Hayır | Sayfalama başlangıç konumu |
Cevap
Yanıt Örneği
{
"data": [
{
"id": "00000000-0000-4000-8000-000000000001",
"featureKey": "ai.chat.multi_agent",
"status": "completed",
"startedAt": "2026-03-17T10:00:00.000Z",
"finishedAt": "2026-03-17T10:00:12.000Z"
}
],
"meta": {
"total": 1,
"limit": 10,
"offset": 0
}
}Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
id | string | Çalıştırma kimliği |
featureKey | string | Çalıştırmayı tetikleyen özellik |
status | string | queued, running, completed, failed, cancelled |
startedAt | string | ISO 8601 |
finishedAt | string | null | ISO 8601 veya null |
Kod Örnekleri
const params = new URLSearchParams({
featureKey: "ai.chat.multi_agent",
status: "completed",
limit: "10",
});
const res = await fetch(`https://api.chainabit.com/api/v1/ai/runs?${params}`, {
headers: { Authorization: `Bearer ${TOKEN}` },
});
const { data, meta } = await res.json();import requests
res = requests.get(
f"{BASE_URL}/ai/runs",
headers={"Authorization": f"Bearer {TOKEN}"},
params={"featureKey": "ai.chat.multi_agent", "status": "completed", "limit": 10},
)
body = res.json()GET /ai/runs/:runId
Tek bir çalıştırmanın ayrıntılarını alın.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
Çalıştırma oluştur yanıtındaki runId değerini $RUN_ID olarak kullanın.
Cevap
Yanıt Örneği
{
"id": "00000000-0000-4000-8000-000000000001",
"featureKey": "ai.chat.multi_agent",
"status": "completed",
"result": {
"text": "The response is complete."
},
"startedAt": "2026-03-17T10:00:00.000Z",
"finishedAt": "2026-03-17T10:00:12.000Z",
"createdAt": "2026-03-17T10:00:00.000Z"
}Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
id | string | Çalıştırma kimliği |
featureKey | string | Çalıştırmayı tetikleyen özellik |
status | string | queued, running, completed, failed, cancelled |
result | unknown | Herkese açık çalıştırma sonucu; erişim kısıtlanabilir |
startedAt | string | null | ISO 8601 |
finishedAt | string | null | ISO 8601 veya null |
createdAt | string | ISO 8601 |
Kod Örnekleri
const runId = process.env.RUN_ID; // id of the run to fetch
const res = await fetch(`https://api.chainabit.com/api/v1/ai/runs/${runId}`, {
headers: { Authorization: `Bearer ${TOKEN}` },
});
const run = await res.json();import os
import requests
run_id = os.environ["RUN_ID"] # id of the run to fetch
res = requests.get(
f"{BASE_URL}/ai/runs/{run_id}",
headers={"Authorization": f"Bearer {TOKEN}"},
)
run = res.json()GET /ai/runs/:runId/steps
Bir çalıştırmada yürütülen tüm adımları listeleyin.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
Çalıştırma oluştur yanıtındaki runId değerini $RUN_ID olarak kullanın.
Cevap
Yanıt Örneği
[
{
"id": "00000000-0000-4000-8000-000000000003",
"stepIndex": 0,
"stepType": "llm_call",
"tokensUsed": 1250,
"durationMs": 3400,
"createdAt": "2026-03-17T10:00:01.000Z"
}
]Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
id | string | Adım kimliği |
stepIndex | number | Adımın çalıştırmadaki sırası |
stepType | string | Adım türü (ör. llm_call) |
tokensUsed | number (isteğe bağlı) | Jeton kullanımı |
durationMs | number (isteğe bağlı) | Milisaniye cinsinden süre |
createdAt | string | ISO 8601 |
contentRedacted | boolean (isteğe bağlı) | Çağıran adım içeriğine erişemediğinde true |
Kod Örnekleri
const runId = process.env.RUN_ID; // id of the run to list steps for
const res = await fetch(`https://api.chainabit.com/api/v1/ai/runs/${runId}/steps`, {
headers: { Authorization: `Bearer ${TOKEN}` },
});
const steps = await res.json();import os
import requests
run_id = os.environ["RUN_ID"] # id of the run to list steps for
res = requests.get(
f"{BASE_URL}/ai/runs/{run_id}/steps",
headers={"Authorization": f"Bearer {TOKEN}"},
)
steps = res.json()GET /ai/runs/:runId/stream
Bir çalıştırma yürütülürken gerçek zamanlı güncellemeleri almak için Sunucu Tarafından Gönderilen Olaylar akışına bağlanın.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
Çalıştırma oluştur yanıtındaki runId değerini $RUN_ID olarak kullanın.
Cevap
Yanıt Örneği
Özellik çalıştırmaları tamamlanan yanıtı message.completed ile gönderir; ardından run.settlement.completed son olayını iletir.
event: message.completed
data: {"eventId":1,"type":"message.completed","runId":"00000000-0000-4000-8000-000000000001","timestamp":"...","payload":{"content":"Based on your completion history data, I recommend starting with smaller goals.","deliveryState":"committed"}}
event: run.settlement.completed
data: {"eventId":2,"type":"run.settlement.completed","runId":"00000000-0000-4000-8000-000000000001","timestamp":"...","payload":{"status":"completed"}}Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
eventId | number | Bu çalıştırma için sürekli artan olay sayacı |
type | string | SSE olay türü — tam katalog için SSE akışı referansına bakın |
runId | string | Çalıştırma UUID değeri |
timestamp | string | ISO 8601 olay zaman damgası |
payload | object | Olaya özgü veriler (ör. { content } message.completed için) |
Kod Örnekleri
// Node.js: npm install eventsource@4
import { EventSource } from 'eventsource';
const runId = process.env.RUN_ID; // id of the run to stream
const es = new EventSource(
`https://api.chainabit.com/api/v1/ai/runs/${runId}/stream`,
{
fetch: (input, init) => fetch(input, {
...init,
headers: { ...init.headers, Authorization: `Bearer ${TOKEN}` },
}),
}
);
es.addEventListener('message.completed', (e) => {
const { payload } = JSON.parse(e.data);
process.stdout.write(payload.content);
});
es.addEventListener('run.settlement.completed', () => es.close());
es.addEventListener('run.failed', (e) => {
console.error('Run failed:', JSON.parse(e.data));
es.close();
});
['run.error', 'run.cancelled', 'run.degraded']
.forEach((type) => es.addEventListener(type, () => es.close()));import os
import sseclient
import requests
import json
run_id = os.environ["RUN_ID"] # id of the run to stream
with requests.get(
f"{BASE_URL}/ai/runs/{run_id}/stream",
headers={
"Authorization": f"Bearer {TOKEN}",
"Accept": "text/event-stream",
},
stream=True,
) as response:
response.raise_for_status()
client = sseclient.SSEClient(response)
for event in client.events():
if event.event == "message.completed":
data = json.loads(event.data)
print(data["payload"]["content"], end="", flush=True)
elif event.event in {"run.settlement.completed", "run.failed", "run.error", "run.cancelled", "run.degraded"}:
breakPOST /ai/runs/:runId/cancel
Şu anda çalışan bir çalıştırmayı iptal edin.
Kimlik Doğrulama: JWT Taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
Çalıştırma oluştur yanıtındaki runId değerini $RUN_ID olarak kullanın.
Cevap
Yanıt Örneği
{
"cancelled": true
}Yanıt Alanları
| Alan | Tür | Açıklama |
|---|---|---|
cancelled | boolean | Çalıştırma iptal edildiyse true; iptal etme yetkiniz yoksa veya çalıştırma zaten tamamlandıysa false |
Kimler iptal edebilir. Hesap sahipleri ve yöneticileri isteğin çalıştığı çalışma alanındaki herhangi bir çalıştırmayı iptal edebilir; diğer üyeler yalnızca kendi başlattıkları çalıştırmaları iptal edebilir. Hesaptan çıkarılmış veya askıya alınmış bir üye, kendi başlattıkları da dahil olmak üzere oradaki hiçbir çalıştırmayı iptal edemez. Mevcut olmayan bir
runIdya da başka bir hesapta veya çalışma alanında olup sizin başlatmadığınız bir çalıştırma403ile reddedilir. Diğer tüm retler{ "cancelled": false }döndürür; bu, zaten tamamlanmış bir çalıştırma için verilen yanıtla aynıdır, bu yüzden yanıt hangi durumun geçerli olduğunu açığa vurmaz. İptal en iyi çabadır; halihazırda aktarılan jetonlar geri çekilmez ve yine de faturalandırılabilir.
Kod Örnekleri
const runId = process.env.RUN_ID; // id of the run to cancel
const res = await fetch(`https://api.chainabit.com/api/v1/ai/runs/${runId}/cancel`, {
method: "POST",
headers: { Authorization: `Bearer ${TOKEN}` },
});
const cancellation = await res.json();import os
import requests
run_id = os.environ["RUN_ID"] # id of the run to cancel
res = requests.post(
f"{BASE_URL}/ai/runs/{run_id}/cancel",
headers={"Authorization": f"Bearer {TOKEN}"},
)
cancellation = res.json()POST /ai/runs/:runId/retry
Mevcut bir çalıştırmanın özellik anahtarını ve yeni kullanıcı mesajlarını kullanarak yeni bir çalıştırma oluşturun. Aktif bir abonelik veya uygun satın alınmış krediler ile özelliğe erişim gerekir.
Kimlik Doğrulama: JWT taşıyıcı jetonu + aktif AI yetkisi gereklidir.
İstek
Çalıştırma oluştur yanıtındaki runId değerini $RUN_ID olarak kullanın. Idempotency-Key başlığı ve 1–50 kullanıcı mesajından oluşan bir messages dizisi gönderin.
{ "messages": [{ "role": "user", "content": "Try this task again" }] }Yanıt
Yanıt, çalıştırma oluşturma isteğiyle aynı requestId, isteğe bağlı runId ve result alanlarını içerir.
{
"requestId": "00000000-0000-4000-8000-000000000004",
"runId": "00000000-0000-4000-8000-000000000005",
"result": { "finishReason": "running", "text": "" }
}Kod Örnekleri
const runId = process.env.RUN_ID;
const idempotencyKey = crypto.randomUUID(); // Keep this key when retrying the same request.
const res = await fetch(`https://api.chainabit.com/api/v1/ai/runs/${runId}/retry`, {
method: "POST",
headers: {
Authorization: `Bearer ${TOKEN}`,
"Content-Type": "application/json",
"Idempotency-Key": idempotencyKey,
},
body: JSON.stringify({ messages: [{ role: "user", content: "Try this task again" }] }),
});
const { requestId, runId: newRunId, result } = await res.json();import os
import requests
import uuid
run_id = os.environ["RUN_ID"]
idempotency_key = str(uuid.uuid4()) # Keep for retries of this request.
res = requests.post(
f"{BASE_URL}/ai/runs/{run_id}/retry",
headers={"Authorization": f"Bearer {TOKEN}", "Idempotency-Key": idempotency_key},
json={"messages": [{"role": "user", "content": "Try this task again"}]},
)
result = res.json() # requestId, optional runId, result