Responses
OpenAI Responses API support for xsAI.
npm i @xsai-ext/responsesThe xsAI Responses API implementation, primarily targeting Open Responses.
Responses API support is experimental and may change significantly in minor version updates.
Usage
Use this package when you explicitly need Responses API semantics instead of Chat Completions.
Basic
import { } from '@xsai-ext/responses'
import { } from 'node:process'
const { , , , } = ({
: .!,
: 'https://api.openai.com/v1/',
: 'Why is the sky blue?',
: 'You are a helpful assistant.',
: 'gpt-5.5',
: { : 'low' },
})
let = ''
for await (const of ) {
+=
}
let = ''
for await (const of ) {
+=
}
.()
.()
.(await )
.(await )Input
import { } from '@xsai-ext/responses'
import { } from 'node:process'
const { } = ({
: .!,
: 'https://api.openai.com/v1/',
: [
{
: [{
: 'Answer briefly and mention only what is clearly visible.',
: 'input_text',
}],
: 'developer',
: 'message',
},
{
: [
{
: 'What is in this image?',
: 'input_text',
},
{
: 'https://upload.wikimedia.org/wikipedia/commons/3/3f/Fronalpstock_big.jpg',
: 'input_image',
},
],
: 'user',
: 'message',
},
],
: 'gpt-5.5',
})
let = ''
for await (const of ) {
+=
}
.()Tool calling
@xsai-ext/responses can automatically execute tools and feed the tool results back into the next Responses step.
import { , } from '@xsai-ext/responses'
import { } from '@xsai/tool'
import { } from 'node:process'
import * as from 'zod'
const = await ({
: 'Adds two numbers',
: ({ , }) => (.() + .()).(),
: 'add',
: .({
: .().('First number'),
: .().('Second number'),
}),
})
const { , } = ({
: .!,
: 'https://api.openai.com/v1/',
: 'What is 12 + 30? Use the add tool.',
: 'You are a helpful assistant.',
: 'gpt-5.5',
: (2),
: 'required',
: [],
})
let = ''
for await (const of ) {
+=
}
.()
.(await )Event streams
This package exposes two event layers:
fullStream: raw Responses API streaming eventseventStream: normalized xsAI events such astext.delta,reasoning.delta,tool-call.start, andstep.done
Use fullStream if you need protocol-level fidelity. Use eventStream if you want a smaller, implementation-oriented event surface.
import { } from '@xsai-ext/responses'
import { } from 'node:process'
const { , } = ({
: .!,
: 'https://api.openai.com/v1/',
: 'Give me a one sentence answer.',
: 'gpt-5.5',
})
for await (const of ) {
.(.)
}
for await (const of ) {
.(.)
}Return value
responses() returns:
textStream: streamed assistant text deltasreasoningTextStream: streamed reasoning deltas when the model emits themeventStream: normalized xsAI eventsfullStream: raw Responses API eventsinput: normalized Responses input itemssteps: completed step list with text, tool calls, tool results, finish reason, and usageusage: usage for the latest completed steptotalUsage: accumulated usage across all steps
Notes
- This package only supports streaming mode. Do not pass
stream. inputaccepts either a plain string or Responses API item arrays.toolsuses the sameToolshape as the rest of xsAI.stopWhenand related helpers such asstepCountAtLeast,and,or,not, andhasToolCallare re-exported from this package.
