Using the nilAI SDKs

Follow these steps to integrate nilAI into your application using our SDKs.

1. Register a DID

Go to the API keys page and register a Public DID. Save the private key securely - you'll need it for SDK configuration.

2. Install the SDK

pnpm install @nillion/nilai-ts

3. Make a completion

import { NilaiOpenAIClient, NilAuthInstance } from "@nillion/nilai-ts";

const API_KEY = "YOUR_PRIVATE_KEY_HERE";

async function main() {
  // Initialize the client in API key mode
  const client = new NilaiOpenAIClient({
    baseURL: "https://api.nilai.nillion.network/nuc/v1/",
    apiKey: API_KEY,
  });

  // Make a request to the Nilai API
  const response = await client.chat.completions.create({
    model: "openai/gpt-oss-20b",
    messages: [
      { role: "user", content: "Hello! Can you help me with something?" }
    ],
  });

  console.log(`Response: ${response.choices[0].message.content}`);
}

// Run the example
main().catch(console.error);