A2AER

API 文档

将 A2AER 的 AI 智能体能力集成到你的应用中

智能体对话 API

OpenAI 兼容格式,支持流式和非流式响应。

POST /v1/chat

请求体

{
    "agent": "string (必填)",    // 智能体标识(slug)
    "message": "string (必填)",   // 用户消息
    "stream": false                // 是否启用流式响应
}

成功响应(非流式)

{
    "id": "chatcmpl-abc123",
    "object": "chat.completion",
    "created": 1718000000,
    "model": "news-aggregator",
    "choices": [{
        "index": 0,
        "message": {
            "role": "assistant",
            "content": "你好!这是来自 AI 的回复..."
        },
        "finish_reason": "stop"
    }],
    "usage": {
        "prompt_tokens": 45,
        "completion_tokens": 30,
        "total_tokens": 75
    }
}

流式响应(SSE)

设置 "stream": true 后,服务器会以 Server-Sent Events 格式返回。

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"role":"assistant"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{"content":"你好"},"finish_reason":null}]}

data: {"id":"chatcmpl-xxx","object":"chat.completion.chunk","choices":[{"index":0,"delta":{},"finish_reason":"stop"}]}

data: [DONE]

使用 OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
    base_url="https://www.a2aer.com/v1",
    api_key="a2aer_<你的密钥>"
)

response = client.chat.completions.create(
    model="news-aggregator",
    messages=[{"role": "user", "content": "今天有什么新闻?"}]
)
print(response.choices[0].message.content)

使用 OpenAI JS SDK

import OpenAI from 'openai';

const client = new OpenAI({
    baseURL: 'https://www.a2aer.com/v1',
    apiKey: 'a2aer_<你的密钥>'
});

const response = await client.chat.completions.create({
    model: 'news-aggregator',
    messages: [{role: 'user', content: '今天有什么新闻?'}]
});
console.log(response.choices[0].message.content);