Ainative Chat Completions
/install ainative-chat-completions
AINative Chat Completions
Endpoint
POST https://api.ainative.studio/v1/public/chat/completions
Auth: X-API-Key: ak_... or Authorization: Bearer \x3Cjwt>
Basic Request
import requests
response = requests.post(
"https://api.ainative.studio/v1/public/chat/completions",
headers={"X-API-Key": "ak_your_key"},
json={
"model": "claude-3-5-sonnet-20241022",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is ZeroDB?"}
],
"temperature": 0.7,
"max_tokens": 1024
}
)
data = response.json()
print(data["choices"][0]["message"]["content"])
print(f"Tokens used: {data['usage']['total_tokens']}")
Streaming (SSE)
import requests
with requests.post(
"https://api.ainative.studio/v1/public/chat/completions",
headers={"X-API-Key": "ak_your_key"},
json={"model": "claude-3-5-sonnet-20241022",
"messages": [{"role": "user", "content": "Count to 5"}],
"stream": True},
stream=True
) as resp:
for line in resp.iter_lines():
if line and line.startswith(b"data: "):
chunk = line[6:]
if chunk != b"[DONE]":
import json
delta = json.loads(chunk)["choices"][0]["delta"]
print(delta.get("content", ""), end="", flush=True)
React SDK — useChat Hook
npm install @ainative/react-sdk
import { AINativeProvider, useChat } from '@ainative/react-sdk';
function App() {
return (
\x3CAINativeProvider config={{ apiKey: 'ak_your_key' }}>
\x3CChatComponent />
\x3C/AINativeProvider>
);
}
function ChatComponent() {
const { messages, sendMessage, isLoading, error } = useChat({
model: 'claude-3-5-sonnet-20241022',
systemPrompt: 'You are a helpful assistant.',
});
const handleSend = () => sendMessage('Hello!');
return (
\x3Cdiv>
{messages.map((msg, i) => (
\x3Cdiv key={i}>\x3Cb>{msg.role}:\x3C/b> {msg.content}\x3C/div>
))}
\x3Cbutton onClick={handleSend} disabled={isLoading}>
{isLoading ? 'Thinking...' : 'Send'}
\x3C/button>
{error && \x3Cp>Error: {error.message}\x3C/p>}
\x3C/div>
);
}
Next.js — Server Action + Streaming
npm install @ainative/next-sdk
// app/api/chat/route.ts
import { createServerClient } from '@ainative/next-sdk/server';
export async function POST(request: Request) {
const { messages } = await request.json();
const client = createServerClient({ apiKey: process.env.AINATIVE_API_KEY! });
const stream = await client.chat.completions.create({
model: 'claude-3-5-sonnet-20241022',
messages,
stream: true,
});
return new Response(stream.body, {
headers: { 'Content-Type': 'text/event-stream' }
});
}
Available Models
| Model | Context | Best For |
|---|---|---|
claude-3-5-sonnet-20241022 |
200k | General purpose (default) |
claude-3-5-haiku-20241022 |
200k | Fast, low cost |
claude-3-opus-20240229 |
200k | Complex reasoning |
gpt-4o |
128k | OpenAI fallback |
Request Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
model |
string | required | Model ID |
messages |
array | required | Conversation history |
stream |
boolean | false | Enable SSE streaming |
temperature |
float | 0.7 | Randomness (0-1) |
max_tokens |
int | 1024 | Max response length |
system |
string | — | System prompt (alternative) |
Credit Costs
Credits are consumed per token. Check balance before high-volume usage:
balance = requests.get(
"https://api.ainative.studio/api/v1/public/credits/balance",
headers={"X-API-Key": "ak_your_key"}
).json()
print(f"Remaining: {balance['remaining_credits']}")
Error Handling
| Status | Meaning | Action |
|---|---|---|
| 401 | Invalid API key | Check key format: ak_... |
| 402 | Insufficient credits | Top up or upgrade plan |
| 429 | Rate limit | Back off, retry with exponential delay |
| 503 | Model unavailable | Retry or use fallback model |
References
docs/api/CHAT_COMPLETION_API_REFERENCE.md(757 lines — full spec)src/backend/app/api/v1/endpoints/managed_chat.pypackages/sdks/react/src/hooks/useChat.tspackages/sdks/nextjs/src/
- Make sure OpenClaw is installed (local or Docker)
- Run the install command in chat:
/install ainative-chat-completions - After installation, invoke the skill by name or use
/ainative-chat-completions - Provide required inputs per the skill's parameter spec and get structured output
What is Ainative Chat Completions?
Help agents build conversational AI with AINative's Chat Completions API. Use when (1) Building a chatbot or AI assistant, (2) Implementing streaming respons... It is an AI Agent Skill for Claude Code / OpenClaw, with 103 downloads so far.
How do I install Ainative Chat Completions?
Run "/install ainative-chat-completions" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.
Is Ainative Chat Completions free?
Yes, Ainative Chat Completions is completely free, licensed under MIT-0. You can download, install and use it at no cost.
Which platforms does Ainative Chat Completions support?
Ainative Chat Completions is cross-platform and runs anywhere OpenClaw / Claude Code is available (cross-platform).
Who created Ainative Chat Completions?
It is built and maintained by Toby Morning (@urbantech); the current version is v1.0.0.