[Discovery Engine] streamAnswer is typed as one AnswerQueryResponse, but REST returns frame arrays
Description
@googleapis/discoveryengine exposes the REST servingConfigs.streamAnswer method as if the default parsed response is one Schema$GoogleCloudDiscoveryengineV1AnswerQueryResponse.
However, direct REST streamAnswer returns a JSON array of AnswerQueryResponse frames. With the default generated method, res.data is that array at runtime, while TypeScript and the generated example tell users to treat res.data as a single object. Typed code can therefore read res.data.answerQueryToken or res.data.answer?.relatedQuestions and get undefined, even though those fields are present in the returned frames.
This is not an answer-quality issue and does not require any live Google call to reproduce. The fixture below is a redacted HTTP 200 direct REST streamAnswer body from Discovery Engine / Vertex AI Search.
Package / source
- Package:
@googleapis/[email protected] - Repo commit checked:
9e92f535023f86df98d8a9dcbdf7777434e3124f - Generated method:
src/apis/discoveryengine/v1.ts,projects.locations.dataStores.servingConfigs.streamAnswer - Source lines: https://github.com/googleapis/google-api-nodejs-client/blob/9e92f535023f86df98d8a9dcbdf7777434e3124f/src/apis/discoveryengine/v1.ts#L57079-L57166
The generated comment says the method is streaming and returns multiple AnswerQueryResponse messages, but the default overload returns Promise<GaxiosResponseWithHTTP2<Schema$GoogleCloudDiscoveryengineV1AnswerQueryResponse>>.
Reproduction
Create these files and run one command:
npm install && npm run repropackage.json:
{
"type": "module",
"scripts": {
"repro": "node repro.mjs && tsc --noEmit --strict --target es2022 --lib es2022 --module nodenext --moduleResolution nodenext typecheck.ts"
},
"dependencies": {
"@googleapis/discoveryengine": "30.0.0",
"@types/node": "24.10.1",
"nock": "14.0.10",
"typescript": "5.9.3"
}
}repro.mjs:
import fs from 'node:fs';
import nock from 'nock';
import {discoveryengine} from '@googleapis/discoveryengine';
const fixture = JSON.parse(fs.readFileSync('./fixture.json', 'utf8'));
const servingConfig =
'projects/testing-repos-489801/locations/global/collections/default_collection/dataStores/large-session-details-20260618-025044-m6sk/servingConfigs/default_search';
nock.disableNetConnect();
nock('https://discoveryengine.googleapis.com')
.post(`/v1/${servingConfig}:streamAnswer`)
.query(true)
.reply(200, fixture, {'content-type': 'application/json'});
const api = discoveryengine('v1');
const res = await api.projects.locations.collections.dataStores.servingConfigs.streamAnswer({
servingConfig,
requestBody: {query: {text: 'offline replay'}},
});
const framesWithRelatedQuestions = res.data.filter(
frame => frame.answer?.relatedQuestions?.length
);
const framesWithTokens = res.data.filter(frame => frame.answerQueryToken);
console.log(`Array.isArray(res.data): ${Array.isArray(res.data)}`);
console.log(`res.data.answerQueryToken: ${String(res.data.answerQueryToken)}`);
console.log(`res.data.answer?.relatedQuestions: ${String(res.data.answer?.relatedQuestions)}`);
console.log(`frame count: ${res.data.length}`);
console.log(`frames with answerQueryToken: ${framesWithTokens.length}`);
console.log(`frames with relatedQuestions: ${framesWithRelatedQuestions.length}`);
console.log(`first relatedQuestions count: ${framesWithRelatedQuestions[0]?.answer.relatedQuestions.length ?? 0}`);typecheck.ts:
import {discoveryengine_v1} from '@googleapis/discoveryengine';
const api = new discoveryengine_v1.Discoveryengine({});
const servingConfig =
'projects/testing-repos-489801/locations/global/collections/default_collection/dataStores/large-session-details-20260618-025044-m6sk/servingConfigs/default_search';
async function main() {
const res =
await api.projects.locations.collections.dataStores.servingConfigs.streamAnswer({
servingConfig,
requestBody: {query: {text: 'offline replay'}},
});
// These compile because streamAnswer is typed as a single AnswerQueryResponse.
const token: string | null | undefined = res.data.answerQueryToken;
const relatedQuestions: string[] | undefined =
res.data.answer?.relatedQuestions ?? undefined;
// This is the runtime shape for valid REST streamAnswer output, but the
// generated default type rejects it.
// @ts-expect-error streamAnswer is typed as unary, not array-of-frame.
const frameCount: number = res.data.length;
console.log(token, relatedQuestions, frameCount);
}
void main();fixture.json (redacted HTTP 200 direct REST streamAnswer body)[
{
"answer": {
"state": "STREAMING",
"steps": [
{
"state": "SUCCEEDED",
"description": "Rephrase the query and search.",
"actions": [
{
"searchAction": {
"query": "For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, what are the alpha, beta, gamma, and delta review requirements? Include citations."
},
"observation": {
"searchResults": [
{
"document": "projects/917493783080/locations/global/collections/default_collection/dataStores/large-session-details-20260618-025044-m6sk/branches/0/documents/large-session-include-details-doc",
"structData": {
"body": "Section 1: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 1; the support region is us-west; the effective date is 2026-06-11. Citations should point to this structured source and compare repeated facts across sections. Section 2: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 2; the support region is us-west; the effective date is 2026-06-12. Citations should point to this structured source and compare repeated facts across sections. Section 3: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 3; the support region is us-west; the effective date is 2026-06-13. Citations should point to this structured source and compare repeated facts across sections. Section 4: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 4; the support region is us-west; the effective date is 2026-06-14. Citations should point to this structured source and compare repeated facts across sections. Section 5: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 5; the support region is us-west; the effective date is 2026-06-15. Citations should point to this structured source and compare repeated facts across sections. Section 6: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 6; the support region is us-west; the effective date is 2026-06-16. Citations should point to this structured source and compare repeated facts across sections. Section 7: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 7; the support region is us-west; the effective date is 2026-06-17. Citations should point to this structured source and compare repeated facts across sections. Section 8: For sentinel large_session_include_details_large_session_include_details_20260618-025044_42p3u, alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date-stamped audit note. The section owner is Search Credit QA 8; the support region is us-west; the effective date is 2026-06-18. Citations should point to this structured source and compare repeated facts across sections.",
"source_uri": "agent-search-test://large_session_include_details_20260618-025044_42p3u/large-session-include-details-doc",
"title": "Large session includeAnswerDetails parity sentinel",
"run_id": "large_session_include_details_20260618-025044_42p3u",
"unicode_notes": "Accents: cafe naive facade. Emoji: checkmark OK. Long dash: alpha -- beta. Greek: lambda pi. Japanese: テスト. Arabic: اختبار.",
"version": 1,
"sentinel_token": "large_session_include_details_large_session_include_details_20260618-025044_42p3u",
"facts": "The release code is R-ALPHA-77. The escalation owner is Search Credit QA. The support region is us-west. The policy labels are standard-search and advanced-generative-answer. Reviewers should verify manual review, automatic approval, escalation, and audit evidence."
}
}
]
}
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"references": [
{
"structuredDocumentInfo": {
"document": "projects/917493783080/locations/global/collections/default_collection/dataStores/large-session-details-20260618-025044-m6sk/branches/0/documents/large-session-include-details-doc",
"structData": {},
"title": "Large session includeAnswerDetails parity sentinel"
}
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "For"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": " the sentinel `large_session_include_details_large_session_include_details_20"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "260618-025044_42p3"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "u`, the review requirements are as follows: alpha requires manual review, beta is automatically approved, gamma requires escalation, and delta requires a date"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "-stamped audit note. "
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"endIndex": "276",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "The support region for this sentinel is us-west. "
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "277",
"endIndex": "325",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "The policy labels associated with this sentinel are standard-search and advanced-generative"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "-answer. "
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "326",
"endIndex": "425",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "Reviewers should verify manual review, automatic approval, escalation, and audit evidence. "
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "426",
"endIndex": "516",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "The release code is R-ALPHA-77. "
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "517",
"endIndex": "548",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "The escalation owner is Search Credit QA.\n\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "549",
"endIndex": "590",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "The section"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": " owner and effective date vary across different sections of the source:\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 1: The section owner is Search Credit QA 1, and the effective date is 2026-06-11."
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "675",
"endIndex": "768",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 2: The section owner is Search Credit QA 2, and the effective date is 2026-06-12.\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "769",
"endIndex": "862",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 3: The section owner is Search Credit QA 3, and the effective date is 2026-06"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "-13.\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "863",
"endIndex": "956",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 4: The section owner is Search Credit QA 4, and the effective date is 2026-06-14.\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "957",
"endIndex": "1050",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 5: The section owner is Search Credit QA 5, and the effective date is 2"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "026-06-15.\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"citations": [
{
"startIndex": "1051",
"endIndex": "1144",
"sources": [
{
"referenceId": "0"
}
]
}
]
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDAwMC0yNTIwLTg0YzctMDg5ZTA4MmNlZmNj"
},
{
"answer": {
"state": "STREAMING",
"answerText": "* Section 6: The section owner is Search Credit QA 6, and the effective date is 2026-06-16.\n"
},
"answerQueryToken": "NMwKDAiomezRBhDUgaihAhIkNmEzZGU2MjMtMDASource: googleapis/google-api-nodejs-client