开发者文档 - A2AER
API 文档
将 A2AER 的 AI 智能体能力集成到你的应用中
JavaScript SDK
使用 OpenAI 官方 JS SDK 即可接入 A2AER API。
安装
npm install openai
基本用法
import OpenAI from 'openai';
const client = new OpenAI({
baseURL: 'https://www.a2aer.com/v1',
apiKey: '你的A2AER_API_KEY'
});
// 非流式对话
const response = await client.chat.completions.create({
model: 'news-aggregator',
messages: [{role: 'user', content: '今天有什么新闻?'}]
});
console.log(response.choices[0].message.content);
// 流式对话
const stream = await client.chat.completions.create({
model: 'math-tutor',
messages: [{role: 'user', content: '解方程 2x+5=15'}],
stream: true
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || '');
}
浏览器中使用 fetch
const resp = await fetch('https://www.a2aer.com/v1/chat', {
method: 'POST',
headers: {
'Authorization': 'Bearer 你的A2AER_API_KEY',
'Content-Type': 'application/json'
},
body: JSON.stringify({
agent: 'news-aggregator',
message: '今天有什么新闻?'
})
});
const data = await resp.json();
console.log(data.choices[0].message.content);