返回顶部
a

ainative-chat-completionsAINative聊天补全

Help agents build conversational AI with AINative's Chat Completions API. Use when (1) Building a chatbot or AI assistant, (2) Implementing streaming responses, (3) Using function/tool calling, (4) Tracking credit usage per request, (5) Choosing between streaming and non-streaming. Covers raw API, Python SDK, React SDK, and Next.js patterns. Closes #1522.

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
94
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

ainative-chat-completions

AINative 聊天补全

端点

POST https://api.ainative.studio/v1/public/chat/completions

认证方式: X-API-Key: ak_... 或 Authorization: Bearer

基本请求

python
import requests

response = requests.post(
https://api.ainative.studio/v1/public/chat/completions,
headers={X-API-Key: akyourkey},
json={
model: claude-3-5-sonnet-20241022,
messages: [
{role: system, content: 你是一个乐于助人的助手。},
{role: user, content: 什么是ZeroDB?}
],
temperature: 0.7,
max_tokens: 1024
}
)
data = response.json()
print(data[choices][0][message][content])
print(f使用的令牌数:{data[usage][total_tokens]})

流式传输(SSE)

python
import requests

with requests.post(
https://api.ainative.studio/v1/public/chat/completions,
headers={X-API-Key: akyourkey},
json={model: claude-3-5-sonnet-20241022,
messages: [{role: user, content: 数到5}],
stream: True},
stream=True
) as resp:
for line in resp.iter_lines():
if line and line.startswith(bdata: ):
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 钩子

bash
npm install @ainative/react-sdk

tsx
import { AINativeProvider, useChat } from @ainative/react-sdk;

function App() {
return (
yourkey }}>


);
}

function ChatComponent() {
const { messages, sendMessage, isLoading, error } = useChat({
model: claude-3-5-sonnet-20241022,
systemPrompt: 你是一个乐于助人的助手。,
});

const handleSend = () => sendMessage(你好!);

return (


{messages.map((msg, i) => (
{msg.role}: {msg.content}

))}

{error &&

错误:{error.message}

}

);
}

Next.js — 服务器操作 + 流式传输

bash
npm install @ainative/next-sdk

typescript
// 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.AINATIVEAPIKEY! });

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 }
});
}

可用模型

模型上下文长度最佳用途
claude-3-5-sonnet-20241022200k通用(默认)
claude-3-5-haiku-20241022
200k | 快速、低成本 | | claude-3-opus-20240229 | 200k | 复杂推理 | | gpt-4o | 128k | OpenAI 备用模型 |

请求参数

参数类型默认值描述
model字符串必填模型ID
messages
数组 | 必填 | 对话历史 | | stream | 布尔值 | false | 启用SSE流式传输 | | temperature | 浮点数 | 0.7 | 随机性(0-1) | | max_tokens | 整数 | 1024 | 最大响应长度 | | system | 字符串 | — | 系统提示(替代方式) |

积分费用

积分按令牌消耗。高量使用前请检查余额:

python
balance = requests.get(
https://api.ainative.studio/api/v1/public/credits/balance,
headers={X-API-Key: akyourkey}
).json()
print(f剩余积分:{balance[remaining_credits]})

错误处理

状态码含义处理方式
401无效的API密钥检查密钥格式:ak_...
402
积分不足 | 充值或升级套餐 | | 429 | 速率限制 | 退避,使用指数延迟重试 | | 503 | 模型不可用 | 重试或使用备用模型 |

参考资料

  • - docs/api/CHATCOMPLETIONAPIREFERENCE.md(757行 — 完整规范)
  • src/backend/app/api/v1/endpoints/managedchat.py
  • packages/sdks/react/src/hooks/useChat.ts
  • packages/sdks/nextjs/src/

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 ainative-chat-completions-1776064690 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 ainative-chat-completions-1776064690 技能

通过命令行安装

skillhub install ainative-chat-completions-1776064690

下载

⬇ 下载 ainative-chat-completions v1.0.0(免费)

文件大小: 2.8 KB | 发布时间: 2026-4-14 10:52

v1.0.0 最新 2026-4-14 10:52
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.

Archiver·手机版·闲社网·闲社论坛·智能体自动化市场· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2026 闲社网·AI智能体论坛·AI自动化解决方案·http://xianshe.com

p2p_official_large
返回顶部