JavaScript SDK
مسار كامل في Node.js: مصادقة، إرسال مهمة، بث سجلات، وجلب النتيجة.
التثبيت
# راجع /docs/sdk-guides لاعتماد أسماء الحزم المحدثةمثال كامل
import { DC1RenterClient } from ;<SDK_PACKAGE_FROM_DOCS>;
const baseUrl = ;https://api.dcp.sa;
const apiKey = process.env.DC1_RENTER_KEY!
const client = new DC1RenterClient({ apiKey, baseUrl })
// ) التحقق من المصادقة
const me = await client.me()
console.log(;renter:;, me.email)
// ) إرسال مهمة
const submitted = await client.submitJob({
job_type: ;llm_inference;,
duration_minutes: ,
max_duration_seconds: ,
container_spec: { image_type: ;vllm-serve; },
params: {
model: ;TinyLlama/TinyLlama-.1B-Chat-v1.;,
prompt: ;اكتب نقاط عن سوق GPU اللامركزي.;,
},
})
const jobId = submitted.job_id
console.log(;job_id:;, jobId)
// ) بث السجلات (SSE)
const logRes = await fetch(`${baseUrl}/api/jobs/${jobId}/logs/stream?key=${apiKey}`)
if (!logRes.ok || !logRes.body) throw new Error(;Failed to open log stream;)
const reader = logRes.body.getReader()
const decoder = new TextDecoder()
let done = false
while (!done) {
const { value, done: streamDone } = await reader.read()
if (streamDone) break
const chunk = decoder.decode(value, { stream: true })
for (const line of chunk.split(;\n;)) {
if (!line.startsWith(;data: ;)) continue
const evt = JSON.parse(line.slice())
if (evt.type === ;log;) console.log(;[log];, evt.line)
if (evt.type === ;end;) {
console.log(;[end];, evt.status)
done = true
break
}
}
}
// ) جلب النتيجة
const outputRes = await fetch(`${baseUrl}/api/jobs/${jobId}/output?key=${apiKey}`)
console.log(await outputRes.json())