Skip to content

OpenAI SDK Integration

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

Installation

Python
pip install openai

Basic Setup

Python
from openai import OpenAI
 
client = OpenAI(
    base_url="https://devnet.aimo.network/api/v1",
    api_key="aimo-sk-dev-[your-key]"
)
 
# Simple chat completion
completion = client.chat.completions.create(
    model="provider_pubkey:model_name",
    messages=[
        {"role": "user", "content": "Hello, AI!"}
    ]
)
 
print(completion.choices[0].message.content)

Streaming Responses

Python
stream = client.chat.completions.create(
    model="provider_pubkey:model_name",
    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="")