@nathaniel-runpod-org/sdk
v1.0.0
Published
JavaScript SDK for Runpod
Downloads
1
Readme
js-sdk
JavaScript client sdk for runpod
Example Usage
const { RUNPOD_API_KEY, ENDPOINT_ID } = process.env;
import runpodSdk from "runpod/node-sdk";
const runpod = runpodSdk(RUNPOD_API_KEY);
const endpoint = runpod.endpoint(ENDPOINT_ID);
const result = await endpoint.runsync({
input: {
prompt: "a photo of a horse the size of a Boeing 787",
},
});
Using Endpoints
Once an endpoint has been created, you can send requests to the queue:
const requestId = await endpoint.run({
input: {
prompt: "a photo of a horse the size of a Boeing 787",
},
});
You can check on the status of this request once you have the id:
const status = await endpoint.getStatus(requestId);
If the request has been completed, the status object returned will contain the output
of the request.
If you don't want to manage polling for request completion yourself, you can simply call runsync
, which will enqueue the request and then poll in a loop (by default, once every 10 seconds) until the request completes, fails or times out.
const result = await endpoint.runsync({
input: {
prompt: "a photo of a horse the size of a Boeing 787",
},
});
If you have the id of a request, you can cancel it if it's taking too long or no longer necessary:
await endpoint.cancel(requestId);
For long running applications or troubleshooting, you may want to check the health of the endpoint workers:
const health = await endpoint.getHealth();