← 返回 Skills 市场
React SDK —
Ainative Chat Completions
作者
Toby Morning
· GitHub ↗
· v1.0.0
· MIT-0
103
总下载
0
收藏
1
当前安装
1
版本数
在 OpenClaw 中安装
/install 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...
使用说明 (SKILL.md)
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/
安全使用建议
This skill is documentation/example code for AINative's chat completions and is internally consistent. Before using it: (1) be prepared to supply your AINative API key when you run the examples — the skill itself doesn't store or request keys but the API calls require them; (2) do not paste secrets or sensitive data into prompts that will be sent to the AINative API; (3) verify you install SDK packages (@ainative/react-sdk, @ainative/next-sdk) from trusted sources (npmjs.org or your vetted private registry) and confirm the API endpoint (api.ainative.studio) matches the official provider; (4) note the scanner flagged a 'system-prompt-override' pattern — this appears to be a benign example of a system message, but always review any skill content that instructs agents on system prompts or message manipulation; (5) if you need higher assurance, request the skill author/publisher identity and confirm the SDK package repositories and docs referenced in the SKILL.md are official.
功能分析
Type: OpenClaw Skill
Name: ainative-chat-completions
Version: 1.0.0
The skill bundle provides documentation and code examples for integrating with the AINative Chat Completions API (api.ainative.studio). It contains standard Python, React, and Next.js snippets for API interaction, streaming, and credit management, with no evidence of malicious intent, data exfiltration, or prompt injection attacks in SKILL.md.
能力评估
Purpose & Capability
The name and description match the SKILL.md content: examples for raw HTTP, Python, React and Next.js SDK usage of AINative's chat completions API. The skill does not declare unrelated env vars, binaries, or installs, which is proportionate for documentation/example content.
Instruction Scope
Instructions are limited to making HTTP requests, using SDK hooks, and streaming SSE; they do not instruct reading arbitrary files or unrelated system state. One caveat: the examples include system messages (e.g., "You are a helpful assistant."), which is expected for chat-completion examples but triggered a pattern scanner for 'system-prompt-override' — likely a benign example but worth being aware of (see scan findings).
Install Mechanism
No install spec and no bundled code — instruction-only. This minimizes risk because nothing is written to disk by the skill itself.
Credentials
The SKILL.md shows use of an AINative API key (X-API-Key or process.env.AINATIVE_API_KEY) in examples. The skill does not require or request unrelated credentials or system config paths; requiring an API key is proportional to the documented usage.
Persistence & Privilege
always is false and there is no install step or code that requests persistent presence or modifies other skills or system settings.
如何使用
- 确保已安装 OpenClaw(本地或 Docker 部署)
- 在对话框中输入安装命令:
/install ainative-chat-completions - 安装完成后,直接呼叫该 Skill 的名称或使用
/ainative-chat-completions触发 - 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
AINative Chat Completions v1.0.0 — initial release!
- Introduces Chat Completions API for building chatbots and AI assistants via REST, Python, React, and Next.js.
- Supports streaming (SSE), function/tool calling, and credit usage tracking per request.
- Includes sample code for Python (sync/streaming), React (`useChat` hook), and Next.js server actions.
- Provides model information, key request parameters, credit cost details, and error handling guidance.
- See full API reference and SDK sources for more technical details.
元数据
常见问题
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... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 103 次。
如何安装 Ainative Chat Completions?
在 OpenClaw 或 Claude Code 对话框中运行命令「/install ainative-chat-completions」即可一键安装,无需额外配置。
Ainative Chat Completions 是免费的吗?
是的,Ainative Chat Completions 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。
Ainative Chat Completions 支持哪些平台?
Ainative Chat Completions 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。
谁开发了 Ainative Chat Completions?
由 Toby Morning(@urbantech)开发并维护,当前版本 v1.0.0。
推荐 Skills