OpenAI SDK

Integrate AiMo Network with the official OpenAI SDK

Integrate AiMo Network with the official OpenAI SDK for seamless AI model access using familiar OpenAI-compatible APIs.

Authentication Update: AiMo Network uses wallet-based SIWx authentication. You have three options:

  1. AiMo CLI (simplest) - See AI Agent Guide
  2. AiMo TypeScript SDK (recommended for apps) - See SDK Reference
  3. Manual SIWx (advanced) - See advanced authentication below

The easiest way to use AiMo Network is through the CLI:

# Install CLI
curl -fsSL https://aimo-cli-releases.s3.ap-northeast-1.amazonaws.com/install.sh | sh

# Generate keypair
aimo keygen

# List available models
aimo router list-models

# Chat with any model
aimo chat --model deepseek/deepseek-v3.2 --message "Hello, AI!"

Alternative: Use AiMo TypeScript SDK

For TypeScript/JavaScript applications, use the official SDK which handles authentication automatically:

npm install @aimo.network/client @aimo.network/svm
import { AimoClient } from "@aimo.network/client";
import { SvmClientSigner, SOLANA_MAINNET_CHAIN_ID } from "@aimo.network/svm";
import { createKeyPairSignerFromBytes } from "@solana/kit";
import bs58 from "bs58";
import fs from "fs";

// Load CLI-generated keypair
const keypairData = JSON.parse(
  fs.readFileSync(process.env.HOME + "/.config/aimo/keypair.json", "utf-8")
);

const privateKeyBytes = new Uint8Array(keypairData);
const keypairSigner = await createKeyPairSignerFromBytes(privateKeyBytes);

// Create signer
const signer = new SvmClientSigner({
  signer: keypairSigner,
  chainId: SOLANA_MAINNET_CHAIN_ID,
});

// Create client
const client = new AimoClient({
  signer,
  baseUrl: "https://beta.aimo.network",
});

// Make chat completion
const response = await client.chatCompletions({
  model: "deepseek/deepseek-v3.2",
  messages: [{ role: "user", content: "Hello, AI!" }],
});

const data = await response.json();
console.log(data.choices[0].message.content);

// Streaming
const streamResponse = await client.chatCompletions({
  model: "deepseek/deepseek-v3.2",
  messages: [{ role: "user", content: "Tell me a story" }],
  stream: true,
});

const reader = streamResponse.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;

  const chunk = decoder.decode(value);
  const lines = chunk.split('\n').filter(line => line.trim());
  
  for (const line of lines) {
    if (line.startsWith('data: ') && line.slice(6) !== '[DONE]') {
      const data = JSON.parse(line.slice(6));
      const content = data.choices[0]?.delta?.content;
      if (content) process.stdout.write(content);
    }
  }
}

See the SDK Reference for complete documentation.

Installation

For programmatic SDK usage:

pip install openai
npm install openai

Advanced Authentication

AiMo Network uses SIWx (Sign-In-With-X) wallet-based authentication. The OpenAI SDK requires custom header injection:

import openai
import json
import base64
from datetime import datetime, timedelta
from nacl.signing import SigningKey

# Load your keypair
with open("/home/user/.config/aimo/keypair.json") as f:
    keypair_data = json.load(f)
    secret_key = bytes(keypair_data[:32])
    signing_key = SigningKey(secret_key)

# Generate SIWx signature
def generate_siwx_header(domain="beta.aimo.network"):
    issued_at = datetime.utcnow().isoformat() + "Z"
    expiration_time = (datetime.utcnow() + timedelta(minutes=5)).isoformat() + "Z"
    
    chain_id = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"
    address = signing_key.verify_key.encode().hex()
    
    message = f"""{domain} wants you to sign in with your account:
{chain_id}:{address}

URI: https://{domain}
Version: 1
Chain ID: {chain_id}
Nonce: {int(datetime.utcnow().timestamp())}
Issued At: {issued_at}
Expiration Time: {expiration_time}"""
    
    signature = signing_key.sign(message.encode()).signature
    
    payload = {
        "message": message,
        "signature": base64.b58encode(signature).decode()
    }
    
    return base64.b64encode(json.dumps(payload).encode()).decode()

# Configure client with SIWx authentication
client = openai.OpenAI(
    base_url="https://beta.aimo.network/api/v1",
    api_key="not-used",
    default_headers={
        "Sign-In-With-X": generate_siwx_header()
    }
)

# Simple chat completion
completion = client.chat.completions.create(
    model="deepseek/deepseek-v3.2",
    messages=[
        {"role": "user", "content": "Hello, AI!"}
    ]
)

print(completion.choices[0].message.content)
import OpenAI from "openai";
import * as ed25519 from "@noble/ed25519";
import * as fs from "fs";

// Load keypair
const keypairData = JSON.parse(
  fs.readFileSync("/home/user/.config/aimo/keypair.json", "utf-8")
);
const secretKey = new Uint8Array(keypairData.slice(0, 32));
const publicKey = await ed25519.getPublicKeyAsync(secretKey);

// Generate SIWx signature
async function generateSiwxHeader(domain = "beta.aimo.network") {
  const issuedAt = new Date().toISOString();
  const expirationTime = new Date(Date.now() + 5 * 60 * 1000).toISOString();
  
  const chainId = "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp";
  const address = Buffer.from(publicKey).toString("hex");
  
  const message = `${domain} wants you to sign in with your account:
${chainId}:${address}

URI: https://${domain}
Version: 1
Chain ID: ${chainId}
Nonce: ${Math.floor(Date.now() / 1000)}
Issued At: ${issuedAt}
Expiration Time: ${expirationTime}`;
  
  const signature = await ed25519.signAsync(
    Buffer.from(message),
    secretKey
  );
  
  const payload = {
    message,
    signature: Buffer.from(signature).toString("base64")
  };
  
  return Buffer.from(JSON.stringify(payload)).toString("base64");
}

// Configure client
const client = new OpenAI({
  baseURL: "https://beta.aimo.network/api/v1",
  apiKey: "not-used",
  defaultHeaders: {
    "Sign-In-With-X": await generateSiwxHeader()
  }
});

// Simple chat completion
const completion = await client.chat.completions.create({
  model: "deepseek/deepseek-v3.2",
  messages: [
    { role: "user", content: "Hello, AI!" }
  ]
});

console.log(completion.choices[0].message.content);

Signature Expiration: SIWx signatures expire after 5 minutes. Generate a fresh signature for each request or implement auto-refresh logic.

Streaming Responses

# Using the client configured above
stream = client.chat.completions.create(
    model="deepseek/deepseek-v3.2",
    messages=[{"role": "user", "content": "Tell me a story"}],
    stream=True
)

for chunk in stream:
    if chunk.choices[0].delta.content:
        print(chunk.choices[0].delta.content, end="")
// Using the client configured above
const stream = await client.chat.completions.create({
  model: "deepseek/deepseek-v3.2",
  messages: [{ role: "user", content: "Tell me a story" }],
  stream: true
});

for await (const chunk of stream) {
  if (chunk.choices[0]?.delta?.content) {
    process.stdout.write(chunk.choices[0].delta.content);
  }
}

List Available Models

# Use the CLI to discover models
aimo router list-models
aimo router search-models "deepseek"

Or programmatically:

# Python
models = client.models.list()
for model in models:
    print(model.id)

Next Steps

On this page