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
- Python
- TypeScript
- pip
- uv
pip install nilai-py
uv pip install nilai-py
pnpm install @nillion/nilai-ts
You can either use:
Direct Signingflow as the sole developer / organization orDelegated Signingto provide permissions to another user / organization.
Direct Signing Flow
- Use
https://api.nilai.nillion.network/nuc/v1as the BASE URL - Check available models or query the
/v1/modelsendpoint or - Select an available model and use it with the
/v1/chat/completionsnilAI node endpoint
With OpenAI compatibility, you can use any OpenAI library. Here's an example for querying the gpt-oss-20b model:
- Python
- Typescript
examples/0-api_key_mode.py
loading...
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.
- Next.js
- Python
- Typescript
This flow matches the older secretllm_nextjs_nucs tutorial:
- Server initializes
DelegationTokenServerwithexpirationTimeandtokenMaxUses. - Client initializes
NilaiOpenAIClientwithauthType: AuthType.DELEGATION_TOKEN. - Client produces a delegation request with
client.getDelegationRequest(). - Server creates the delegation token with
server.createDelegationToken(...). - Client sets the token with
client.updateDelegation(...). - 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...
examples/1-delegation_token_mode.py
loading...
examples/1-delegation-token.ts
loading...