diff --git a/js/ai/src/generate/response.ts b/js/ai/src/generate/response.ts index 54fcb7c1b7..d6631e7e5b 100644 --- a/js/ai/src/generate/response.ts +++ b/js/ai/src/generate/response.ts @@ -93,6 +93,13 @@ export class GenerateResponse implements ModelResponseData { ); } + if (this.finishReason === 'length') { + throw new GenerationResponseError( + this, + `Model generated a message that is too long. Finish reason: '${this.finishReason}': ${this.finishMessage}` + ); + } + if (!this.message && !this.operation) { throw new GenerationResponseError( this,