File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -167,7 +167,8 @@ export namespace ProviderError {
167167
168168 export function parseAPICallError ( input : { providerID : ProviderID ; error : APICallError } ) : ParsedAPICallError {
169169 const m = message ( input . providerID , input . error )
170- if ( isOverflow ( m ) || input . error . statusCode === 413 ) {
170+ const body = json ( input . error . responseBody )
171+ if ( isOverflow ( m ) || input . error . statusCode === 413 || body ?. error ?. code === "context_length_exceeded" ) {
171172 return {
172173 type : "context_overflow" ,
173174 message : m ,
Original file line number Diff line number Diff line change @@ -869,6 +869,26 @@ describe("session.message-v2.fromError", () => {
869869 } )
870870 } )
871871
872+ test ( "detects context overflow from context_length_exceeded code in response body" , ( ) => {
873+ const error = new APICallError ( {
874+ message : "Request failed" ,
875+ url : "https://example.com" ,
876+ requestBodyValues : { } ,
877+ statusCode : 422 ,
878+ responseHeaders : { "content-type" : "application/json" } ,
879+ responseBody : JSON . stringify ( {
880+ error : {
881+ message : "Some message" ,
882+ type : "invalid_request_error" ,
883+ code : "context_length_exceeded" ,
884+ } ,
885+ } ) ,
886+ isRetryable : false ,
887+ } )
888+ const result = MessageV2 . fromError ( error , { providerID } )
889+ expect ( MessageV2 . ContextOverflowError . isInstance ( result ) ) . toBe ( true )
890+ } )
891+
872892 test ( "does not classify 429 no body as context overflow" , ( ) => {
873893 const result = MessageV2 . fromError (
874894 new APICallError ( {
You can’t perform that action at this time.
0 commit comments