Skip to main content

Usage

The nilAI SDKs operate under the Direct Signing & Delegated Signing access modes. You will need a Public DID / Private Key to use the SDKs - not a plain API Key.

Getting Started with Private LLMs

pnpm install @nillion/nilai-ts

You can either use:

  • Direct Signing flow as the sole developer / organization or
  • Delegated Signing to provide permissions to another user / organization.

Direct Signing Flow

  1. Use https://api.nilai.nillion.network/nuc/v1 as the BASE URL
  2. Check available models or query the /v1/models endpoint or
  3. Select an available model and use it with the /v1/chat/completions nilAI node endpoint

With OpenAI compatibility, you can use any OpenAI library. Here's an example for querying the gpt-oss-20b model:

examples/0-api-key.ts
loading...

Delegated Signing

To use the delegated signing flow, you need to create a delegation token server.

The server creates delegation tokens and manages their expiration and usage. Then the delegation token allows clients to make requests to the nilAI API.

This flow matches the older secretllm_nextjs_nucs tutorial:

  1. Server initializes DelegationTokenServer with expirationTime and tokenMaxUses.
  2. Client initializes NilaiOpenAIClient with authType: AuthType.DELEGATION_TOKEN.
  3. Client produces a delegation request with client.getDelegationRequest().
  4. Server creates the delegation token with server.createDelegationToken(...).
  5. Client sets the token with client.updateDelegation(...).
  6. Client uses the delegation token to call chat completions and reads response.choices[0].message.content.
nilai/secretllm_nextjs_sdk/app/api/chat-delegation/route.ts
loading...