Node SDK

The Pendra Node SDK lets you call every Pendra model from JavaScript or TypeScript, with streaming and full types. It needs Node.js 20 or later.

Install

bash
$ npm install pendra

End-to-end encryption is built in, with nothing extra to install. The package is on npm.

Send a request

Create a client with your API key, or leave out apiKey and set PENDRA_API_KEY instead.

import { Pendra } from 'pendra';

const client = new Pendra({ apiKey: 'pdr_sk_...' });

const response = await client.chat.completions.create({
  model: 'qwen3.6:27b',
  messages: [{ role: 'user', content: 'What is the capital of Wales?' }],
});
console.log(response.choices[0].message.content);

The client also takes these options:

  • privateInference: true encrypts every request so only your worker can read it. See End-to-end encryption.
  • timeout, in milliseconds. The default is 120,000.

Stream the reply

Set stream: true to print the reply as it's written. The last few chunks carry usage and timing rather than text, which is why the example reads choices[0] with ?..

const stream = await client.chat.completions.create({
  model: 'qwen3.6:27b',
  messages: [{ role: 'user', content: 'Write a poem about London.' }],
  stream: true,
});

for await (const chunk of stream) {
  process.stdout.write(chunk.choices[0]?.delta?.content ?? '');
}

To send many requests at once, see Batch inference.

What you can call

Each guide has a worked example. For every parameter, see the API reference.

MethodFor
client.chat.completions.create() Chat, vision, tools and structured outputs. See Chat.
client.images.generations.create() Generate images from a prompt. See Image generation.
client.audio.transcriptions.create() Turn speech into text. See Audio transcription.
client.audio.speech.create() Turn text into speech. See Text to speech.
client.embeddings.create() Turn text into vectors for search. See Embeddings.
client.rerank.create() Sort documents by relevance to a query. See Reranking.
client.moderations.create() Check text or images for harmful content. See Moderation.
client.models.list() List the models you can call. See Models.

Any other field in a request is sent to the API as it is.

Pendra extras

Every reply has a pendra field on top of the usual ones:

  • response.pendra.worker names the worker that ran it, and response.pendra.request_id is the id to quote to support. On a stream, read stream.worker and stream.requestId after the last chunk.
  • response.pendra.notice explains a reply that looks wrong, such as a model that spent all its max_tokens thinking. See Notices.

To send a request to one particular worker, pass worker_id: '...'.

const response = await client.chat.completions.create({
  model: 'qwen3.6:27b',
  messages: [{ role: 'user', content: 'Hello!' }],
});

const { worker, request_id, notice } = response.pendra ?? {};
console.log(worker?.name, request_id);

if (notice) {
  console.log(notice.code, notice.message);
}

Errors

Every error is an APIError, with a readable message.

ErrorWhen
AuthenticationErrorThe API key is missing or wrong (401).
RateLimitErrorEvery worker for the model is busy (429). Wait for retryAfter seconds and try again.
APIStreamErrorA reply failed after it had started, for example if a worker went offline.
APIStatusErrorAny other error response.
APIConnectionErrorPendra couldn't be reached.
import { Pendra, RateLimitError, APIStreamError } from 'pendra';

try {
  const response = await client.chat.completions.create({
    model: 'qwen3.6:27b',
    messages: [{ role: 'user', content: 'Hello!' }],
  });
} catch (err) {
  if (err instanceof RateLimitError) {
    await new Promise((r) => setTimeout(r, (err.retryAfter ?? 5) * 1000));
    // then try again
  } else if (err instanceof APIStreamError) {
    console.error(err.message, err.requestId);
  } else {
    throw err;
  }
}

A stream that fails part way throws APIStreamError from the loop, and you keep the text that already arrived. So can a request that runs for more than about 80 seconds, such as a long transcription. Quote its requestId if you contact support. For every error code, see Errors & rate limits.