Complete implementation guide and API reference for the Ainoz LLM SDK
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.
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.
npm install ainoz-sdk @solana/web3.js cross-fetch eventemitter3AINOZ_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"
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
})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)model: Model identifier (e.g., "ainoz-compact-v1")prompt: Input text promptwallet: Solana wallet public key (optional)maxTokens: Maximum tokens to generate (optional)temperature: Sampling temperature 0-1 (optional)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')
})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)
}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)
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."Complete TypeScript implementation of the Ainoz SDK for reference or self-hosting.
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;
};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");
}
}export { AinozClient } from "./lib/client";
export * from "./lib/types";streamGenerate() for better UX with lengthy responsesmoderate() before storing on-chainainoz-monorepo/ ├── apps/ │ ├── landing/ # Marketing website │ └── docs/ # Documentation site ├── packages/ │ └── ainoz-sdk/ # Core SDK package └── examples/ # Integration examples
Ready to integrate AI into your Solana app? Install the SDK and start generating content today.