Responses
The Responses class provides methods to reason over the content in a knowledge store and generate responses.
Methods
Create a response
Description: This method uses Jockey to reason over content in a knowledge store and create a response. It uses Open Responses conventions for input items and streaming events.
Before you use this method, you must create an asset, create a knowledge store, and add the asset to the knowledge store as an item.
Multi-turn conversations: Supported via a session identifier. The first request implicitly creates a session; subsequent requests pass the returned identifier to continue the conversation.
Selections: By default, Jockey reasons over every item in the knowledge store. To narrow the scope, set the optional selections parameter to specific items or item collections, then reference each one with a {{sel:N}} token in the content field of an input item (N is the zero-based position in the selections array). The narrowing is applied at the prompt level; the knowledge store does not block access to other items.
Streaming: To receive the response as Server-Sent Events (SSE), use Stream a response.
Web sources: Jockey can search public web sources while it generates a response. To allow this, include { "type": "jockey:web_search" } in the tools array. The response can then cite these sources alongside content from the knowledge store, as url_citation annotations. Jockey decides whether to use an available tool, so enabling web search does not guarantee a search. To make a search more likely, explicitly tell Jockey what information to look up in input or instructions. A prompt that asks Jockey to search the web does not enable web search by itself. If you omit tools or pass [], Jockey cannot search public web sources, even when the prompt requests it.
Function signature and example:
Parameters
The ResponseInputItem object contains the following properties:
The ResponseToolInput object contains the following property:
The ResponseSelection object contains the following properties:
The TextParam object contains the following property:
When format.type is json_schema, the format object contains the following properties:
Return value
Returns a ResponseObject object. The ResponseObject object contains the following properties:
The ResponseOutputItem object contains the following properties:
The ResponseOutputContentPart object contains the following properties:
For the full list of fields on each citation in the annotations array, see Create a response.
Citations: Each citation identifies a span of the answer text and the source that supports it. Media citations point to knowledge store items and collections, and web citations point to public web sources.
The platform can add new citation types. If you encounter a citation type you do not recognize, keep the response text and display the citations you do recognize.
Citation offsets count Unicode code points, and both bounds are inclusive. Use the offsets of an annotation to locate the text it covers. When multiple annotations cover the same text, keep the source of each one.
API Reference
Related guide
Stream a response
Description: This method uses Jockey to reason over content in a knowledge store and create a response, streamed as Server-Sent Events (SSE). It returns an async-iterable stream of ResponseStreamEvent objects. For the non-streaming variant, see Create a response.
Function signature and example:
Parameters
This method accepts the same parameters as Create a response.
Return value
Returns an async-iterable Stream<ResponseStreamEvent>. Each event has a type field that identifies the event; unlike the response object, events have no object field. For example, response.output_text.delta events deliver incremental output text in a delta field, and a response.completed event signals the end of the stream. When you request intermediate outputs, the response.output_item.added event delivers each message with its phase field already set, so you can identify intermediate output or the answer before any of its text streams in. Citations do not stream in with the text: the annotations array is empty while a content part is being generated, and the response.content_part.done event contains the completed part with all of its citations.