classifyOpenAIError (openai/errors.ts)

sdk-python · strands-ts/src/models/openai/errors.ts · typescript · Apache-2.0
integration, Integration / API

Classifies OpenAI SDK errors into context overflow or throttling categories.

// Source: https://github.com/strands-agents/harness-sdk | License: Apache-2.0
// Provided via justclaw.it.com; keep this notice with the code.
/**
 * Shared error classification for the OpenAI model provider.
 *
 * @internal
 */

/**
 * Error message patterns that indicate context window overflow.
 *
 * @see https://platform.openai.com/docs/guides/error-codes
 */
// Union of overflow phrases observed across OpenAI responses, matched
// case-insensitively. Lowercased here so the comparison is a single
// ``toLowerCase`` on the error message.
const CONTEXT_WINDOW_OVERFLOW_PATTERNS = [
  'maximum context length',
  'context_length_exceeded',
  'too many tokens',
  'context length',
  'input is too long for requested model',
  'input length and `max_tokens` exceed context limit',
  'too many 

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key