vercel/ai · error · Error
google.interactions: cannot stream a background interaction
Error message
google.interactions: cannot stream a background interaction without an id.
What it means
streamGoogleInteractionEvents consumes server-sent events for an already-created background interaction, which requires a valid interactionId. When the id string is empty it cannot build the event-source request, so it throws immediately before opening the stream. This guards against programming errors where an id was never assigned or was lost between creating and streaming the interaction.
Source
Thrown at packages/google/src/interactions/stream-google-interactions.ts:53
export function streamGoogleInteractionEvents({
baseURL,
interactionId,
headers,
fetch,
abortSignal,
maxRetries = DEFAULT_MAX_RETRIES,
retryDelayMs = DEFAULT_RETRY_DELAY_MS,
}: {
baseURL: string;
interactionId: string;
headers: Record<string, string | undefined>;
fetch?: FetchFunction;
abortSignal?: AbortSignal;
maxRetries?: number;
retryDelayMs?: number;
}): ReadableStream<ParseResult<GoogleInteractionsEvent>> {
if (interactionId.length === 0) {
throw new Error(
'google.interactions: cannot stream a background interaction without an id.',
);
}
const eventSourceHeaders = {
...headers,
accept: 'text/event-stream',
};
let lastEventId: string | undefined;
let complete = false;
let attempt = 0;
let receivedAnyEventThisAttempt = false;
let currentReader:
| ReadableStreamDefaultReader<ParseResult<GoogleInteractionsEvent>>
| undefined;
/*View on GitHub (pinned to 69428b1f8b)
Solutions
- Ensure the interaction is created first and capture its id from the POST response before streaming.
- Add a truthiness check on the id before calling the streaming API.
- If using a non-background interaction, use the non-streaming or inline path instead of streaming by id.
Example fix
// before
await streamGoogleInteraction({ interactionId: created.id ?? '' });
// after
if (!created.id) throw new Error('interaction id missing from create response');
await streamGoogleInteraction({ interactionId: created.id }); Defensive patterns
Strategy: validation
Validate before calling
if (typeof interactionId !== 'string' || interactionId.length === 0) {
throw new Error('interactionId is required before streaming');
}
await streamGoogleInteraction({ interactionId }); Type guard
function hasInteractionId(v: unknown): v is string {
return typeof v === 'string' && v.length > 0;
} Prevention
- Always capture the id from the create-interaction POST response before streaming.
- Type the id as `string` (not `string | undefined`) after creation to get compiler help.
- Never pass empty-string defaults for ids.
When it happens
Trigger: Calling the interactions streaming path with interactionId set to '' — typically when a variable holding the id was never populated or the create response's id field was not extracted.
Common situations: Destructuring the create-interaction response and missing the id field; passing a user-supplied id that was blank; reordering code so streaming happens before the id is known.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- 'element streams in no-schema mode' functionality not suppor
- 'element streams in object mode' functionality not supported
- Unsupported chunk type: ${_exhaustiveCheck}
- 'element streams in enum mode' functionality not supported.
- Unsupported chunk type: ${_exhaustiveCheck}
AI-assisted analysis of vercel/ai@69428b1f8b (2026-08-30).
Data as JSON: /api/errors/9e881b9d3854b716.
Report an issue: GitHub.