跳转到内容

Node.js 接入(fetch)

这是最通用、最不挑版本的写法:直接用 HTTP 调用。

你只需要准备:

  • OPENAI_API_KEY 环境变量(放你的 su8 codes key)
  • Node.js 18+(自带 fetch
node.mjs
const baseURL = 'https://su8.codes/codex/v1';
const apiKey = process.env.OPENAI_API_KEY;
if (!apiKey) {
throw new Error('Missing OPENAI_API_KEY');
}
async function main() {
const resp = await fetch(`${baseURL}/responses`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${apiKey}`
},
body: JSON.stringify({
model: 'gpt-5.2',
input: [
{
type: 'message',
role: 'user',
content: [{ type: 'input_text', text: '你好' }]
}
]
})
});
const text = await resp.text();
if (!resp.ok) throw new Error(`${resp.status} ${resp.statusText}\\n${text}`);
console.log(text);
}
main();

如果你不知道模型名,先去复制一个: