SDK JavaScript
Node.js integration guide with request/response parity snippets for critical DCP endpoints.
Install
npm install dc1-renter-sdkRenter flow (me -> submit -> logs -> output)
import { DC1RenterClient } from ;dc1-renter-sdk;
const baseUrl = ;https://api.dcp.sa;
const apiKey = process.env.DC1_RENTER_KEY!
const client = new DC1RenterClient({ apiKey, baseUrl })
// ) Validate auth
const me = await client.me()
console.log(;renter:;, me.email)
// ) Submit job
const submitted = await client.submitJob({
providerId: ,
jobType: ;llm_inference;,
durationMinutes: ,
params: {
model: ;TinyLlama/TinyLlama-.1B-Chat-v1.;,
prompt: ;Explain DCP in bullets.;,
},
})
const jobId = submitted.id
console.log(;job_id:;, jobId)
// ) Wait for completion (uses polling internally)
const result = await client.waitForJob(jobId, { timeout: })
console.log(;output:;, result.result)
// Alternatively: stream logs via SSE
const logRes = await fetch(`${baseUrl}/api/jobs/${jobId}/logs/stream`, {
headers: { ;x-renter-key;: apiKey }
})
if (!logRes.ok || !logRes.body) throw new Error(;Failed to open log stream;)
const reader = logRes.body.getReader()
const decoder = new TextDecoder()
for await (const chunk of decoder.decode((await logRes.body.getReader().read()).value, { stream: true }).split(;\n;)) {
if (!chunk.startsWith(;data: ;)) continue
const evt = JSON.parse(chunk.slice())
if (evt.type === ;log;) console.log(;[log];, evt.line)
if (evt.type === ;end;) { console.log(;[end];, evt.status); break }
}Parity snippets (raw fetch)
`POST /api/renters/register`
const registerRes = await fetch(;https://api.dcp.sa/api/renters/register;, {
method: ;POST;,
headers: { ;Content-Type;: ;application/json; },
body: JSON.stringify({
name: ;Fatima Al-Saud;,
email: ;fatima@example.sa;,
organization: ;Riyadh AI Lab;,
use_case: ;llm_inference;,
phone: ;+;,
}),
})
const registerData = await registerRes.json()
if (!registerRes.ok) throw new Error(registerData.error)`POST /api/providers/heartbeat`
const hbRes = await fetch(;https://api.dcp.sa/api/providers/heartbeat;, {
method: ;POST;,
headers: { ;Content-Type;: ;application/json; },
body: JSON.stringify({
api_key: process.env.DC1_PROVIDER_KEY,
gpu_status: {
gpu_name: ;NVIDIA RTX ;,
gpu_vram_mib: ,
gpu_util_pct: ,
temp_c: ,
daemon_version: ;.3.;,
},
}),
})
const hbData = await hbRes.json()
if (!hbRes.ok) throw new Error(hbData.error)`GET /api/admin/dashboard`
const adminRes = await fetch(;https://api.dcp.sa/api/admin/dashboard;, {
headers: { ;x-admin-token;: process.env.DC1_ADMIN_TOKEN! },
})
const adminData = await adminRes.json()
if (!adminRes.ok) throw new Error(adminData.error)
console.log(adminData.stats)Notes
- Error payloads are always JSON: `{ error: string }`.
- Job submit auth: `x-renter-key` header (or `?key=` / `?renter_key=` query fallback).
- Admin auth: `x-admin-token` header (Bearer token also accepted).