From 3a48e2aab1ed78a6c80cc3c487ab7239c0f8aa0c Mon Sep 17 00:00:00 2001 From: Joaquin Gimenez Date: Wed, 22 Jan 2025 15:02:32 -0600 Subject: [PATCH] Add returnRawResponse to AI binding options --- src/cloudflare/internal/ai-api.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/cloudflare/internal/ai-api.ts b/src/cloudflare/internal/ai-api.ts index 5aa00752710..4ff2ad4f4a0 100644 --- a/src/cloudflare/internal/ai-api.ts +++ b/src/cloudflare/internal/ai-api.ts @@ -23,7 +23,8 @@ export type SessionOptions = { export type AiOptions = { gateway?: GatewayOptions; - + /** If true it will return a Response object */ + returnRawResponse?: boolean; prefix?: string; extraHeaders?: object; /* @@ -142,6 +143,10 @@ export class Ai { this.aiGatewayLogId = res.headers.get('cf-aig-log-id'); this.lastRequestHttpStatusCode = res.status; + if (this.options.returnRawResponse) { + return res; + } + if (!res.ok) { throw await this._parseError(res); }