| 1216 | } |
| 1217 | |
| 1218 | export function categorizeRetryableAPIError( |
| 1219 | error: APIError, |
| 1220 | ): SDKAssistantMessageError { |
| 1221 | if ( |
| 1222 | error.status === 529 || |
| 1223 | error.message?.includes('"type":"overloaded_error"') |
| 1224 | ) { |
| 1225 | return 'rate_limit' |
| 1226 | } |
| 1227 | if (error.status === 429) { |
| 1228 | return 'rate_limit' |
| 1229 | } |
| 1230 | if (error.status === 401 || error.status === 403) { |
| 1231 | return 'authentication_failed' |
| 1232 | } |
| 1233 | if (error.status !== undefined && error.status >= 408) { |
| 1234 | return 'server_error' |
| 1235 | } |
| 1236 | return 'unknown' |
| 1237 | } |
| 1238 | |
| 1239 | export function getErrorMessageIfRefusal( |
| 1240 | stopReason: BetaStopReason | null, |