Ainoz SDK Documentation

Complete implementation guide and API reference for the Ainoz LLM SDK

Ainoz

Under Active Development

Our dedicated team is working tirelessly to bring you the most advanced on-chain LLM experience on Solana. The Ainoz SDK and dApp are currently in active development, with comprehensive testing and optimization underway to ensure production-ready performance, security, and reliability.

Core SDK Implementation
Smart Contract Integration
Production Deployment

Overview

The Ainoz SDK provides browser and Node.js access to Ainoz LLM via wallet signatures or API keys. It enables text generation, streaming responses, content moderation, and on-chain metadata publishing for Solana-native applications.

Installation

npm install ainoz-sdk @solana/web3.js cross-fetch eventemitter3

Environment Configuration

AINOZ_API_KEY="your-ainoz-api-key"

SOLANA_RPC_URL="https://api.mainnet-beta.solana.com"
SOLANA_RPC_DEVNET="https://api.devnet.solana.com"

AINOZ_RELAYER_URL="https://api.ainoz.xyz"

API Reference

new AinozClient(opts)

Creates a new Ainoz SDK client instance.

import { AinozClient } from 'ainoz-sdk'

const ainoz = new AinozClient({
  rpc: solanaConnection,
  relayerUrl: 'https://api.ainoz.xyz',
  apiKey: process.env.AINOZ_API_KEY // optional
})

generateText(opts)

Generates text completion from a prompt.

const result = await ainoz.generateText({
  model: 'ainoz-compact-v1',
  prompt: 'Generate a funny Solana meme',
  wallet: walletPublicKey.toString(),
  maxTokens: 100,
  temperature: 0.7
})

console.log(result.text)
console.log(result.requestId)
console.log(result.tokensUsed)

Parameters:

  • model: Model identifier (e.g., "ainoz-compact-v1")
  • prompt: Input text prompt
  • wallet: Solana wallet public key (optional)
  • maxTokens: Maximum tokens to generate (optional)
  • temperature: Sampling temperature 0-1 (optional)

streamGenerate(opts)

Streams text generation in real-time.

const stream = await ainoz.streamGenerate({
  model: 'ainoz-compact-v1',
  prompt: 'Write a thread about Solana',
  wallet: walletPublicKey.toString()
})

stream.on('data', (chunk) => {
  console.log('Received:', chunk)
})

stream.on('end', () => {
  console.log('Stream complete')
})

moderate(text)

Checks content for safety before publishing.

const result = await ainoz.moderate(generatedText)

if (result.flagged) {
  console.log('Content flagged:', result.categories)
} else {
  // Safe to publish
  publishOnChain(generatedText)
}

getRequestStatus(requestId)

Retrieves the status of a previous generation request.

const status = await ainoz.getRequestStatus(requestId)

console.log(status.state) // 'pending' | 'complete' | 'failed'
console.log(status.result)

Browser Usage Example

import { AinozClient } from 'ainoz-sdk'
import { Connection } from '@solana/web3.js'

// Connect wallet
await window.solana.connect()

// Initialize client
const connection = new Connection('https://api.mainnet-beta.solana.com')
const ainoz = new AinozClient({
  rpc: connection,
  relayerUrl: 'https://api.ainoz.xyz'
})

// Generate text
const result = await ainoz.generateText({
  model: 'ainoz-compact-v1',
  prompt: 'Generate a funny Solana meme coin description',
  wallet: window.solana.publicKey.toString()
})

console.log(result.text)
// Output: "AinozCoin — where memes, vibes, and Solana blocks collide."

Architecture

Browser / Node.js Client
↓ wallet signature / API key
Ainoz SDK
↓ authenticated requests
Ainoz Relayer
↓ inference requests
Ainoz Inference Node
↓ optional on-chain publish
Solana Program

SDK Implementation Code

Complete TypeScript implementation of the Ainoz SDK for reference or self-hosting.

/packages/ainoz-sdk/src/lib/types.ts

export type AinozClientOptions = {
  rpc: any;
  relayerUrl: string;
  apiKey?: string;
};

export type GenerateTextParams = {
  model: string;
  prompt: string;
  wallet?: string;
  maxTokens?: number;
  temperature?: number;
};

export type GenerateTextResponse = {
  text: string;
  requestId: string;
  tokensUsed?: number;
};

/packages/ainoz-sdk/src/lib/client.ts

import fetch from "cross-fetch";
import EventEmitter from "eventemitter3";
import {
  AinozClientOptions,
  GenerateTextParams,
  GenerateTextResponse,
} from "./types";

export class AinozClient {
  private rpc: any;
  private relayerUrl: string;
  private apiKey?: string;

  constructor(opts: AinozClientOptions) {
    this.rpc = opts.rpc;
    this.relayerUrl = opts.relayerUrl;
    this.apiKey = opts.apiKey;
  }

  private headers() {
    const h: any = { "Content-Type": "application/json" };
    if (this.apiKey) h["Authorization"] = `Bearer ${this.apiKey}`;
    return h;
  }

  async generateText(
    params: GenerateTextParams
  ): Promise<GenerateTextResponse> {
    const res = await fetch(`${this.relayerUrl}/v1/generate`, {
      method: "POST",
      headers: this.headers(),
      body: JSON.stringify(params),
    });

    if (!res.ok) {
      throw new Error(`Ainoz generateText failed: ${res.status}`);
    }

    return res.json();
  }

  async streamGenerate(params: GenerateTextParams) {
    const emitter = new EventEmitter();

    fetch(`${this.relayerUrl}/v1/generate/stream`, {
      method: "POST",
      headers: this.headers(),
      body: JSON.stringify(params),
    }).then(async (res) => {
      const reader = res.body?.getReader();
      if (!reader) return;

      const decoder = new TextDecoder();
      while (true) {
        const { value, done } = await reader.read();
        if (done) break;
        emitter.emit("data", decoder.decode(value));
      }
      emitter.emit("end");
    });

    return emitter;
  }

  async getRequestStatus(requestId: string) {
    const res = await fetch(
      `${this.relayerUrl}/v1/requests/${requestId}`,
      { headers: this.headers() }
    );
    return res.json();
  }

  async moderate(text: string) {
    const res = await fetch(`${this.relayerUrl}/v1/moderate`, {
      method: "POST",
      headers: this.headers(),
      body: JSON.stringify({ text }),
    });
    return res.json();
  }

  async createOnchainMetadataTx(_: any) {
    throw new Error("Implemented in on-chain helper package");
  }
}

/packages/ainoz-sdk/src/index.ts

export { AinozClient } from "./lib/client";
export * from "./lib/types";

Best Practices

  • Stream long outputs — Use streamGenerate() for better UX with lengthy responses
  • Moderate before publishing — Always run moderate() before storing on-chain
  • Cache prompts — Store request IDs and results to avoid duplicate API calls
  • Prefer wallet auth — Use wallet signatures for public apps; save API keys for backend services

Monorepo Structure

ainoz-monorepo/
├── apps/
│   ├── landing/          # Marketing website
│   └── docs/             # Documentation site
├── packages/
│   └── ainoz-sdk/        # Core SDK package
└── examples/             # Integration examples

Start Building with Ainoz

Ready to integrate AI into your Solana app? Install the SDK and start generating content today.