# Fix BadRequestError: This model's maximum context length is 8191 tokens on OpenAI Embeddings

> OpenAI text-embedding-3-large and text-embedding-3-small reject an entire batch with HTTP 400 if even one string exceeds 8,191 cl100k_base tokens, a common failure when character-count splitters process dense code, base64 strings, or wide Markdown tables (~1.3 chars/token instead of 4). Pre-tokenize with cl100k_base window pooling, or use Voxell Forge structure-aware parent-span ingest ($39/mo Builder).

Canonical URL: https://voxell.ai/errors/openai-embeddings-maximum-context-length-8191-tokens/


## Why Character Splitters (`chunk_size = 24000`) Blow Past `8,191` `cl100k_base` Tokens

English prose averages `~4` characters per token, tempting teams to set character splitters around `25,000` characters. When that pipeline hits OpenAPI YAML, SQL dumps, CJK text, or pipe-delimited financial tables, token density spikes to `1.1..1.6` characters per token (`16,000+` tokens), poisoning the entire `2,048`-item batch with a single `400 BadRequestError`.

## Immediate Python Fix: Exact `cl100k_base` Sliding-Window Pooling

```python
import numpy as np, tiktoken

enc = tiktoken.get_encoding("cl100k_base")

def safe_token_windows(text: str, limit: int = 8000, overlap: int = 256) -> list[list[int]]:
    ids = enc.encode(text, disallowed_special=())
    if len(ids) <= limit:
        return [ids]
    stride = limit - overlap
    return [ids[i : i + limit] for i in range(0, len(ids), stride)]

# Pass token ID arrays directly to OpenAI embeddings.create(input=windows)
# and length-weight + L2-normalize pooled vectors for oversized documents.
```

## Native Structure-Aware Document & Table Ingest on Voxell Forge

Blindly slicing `8,191`-token windows severs Markdown table headers from numeric rows. Voxell Forge parses PDFs, DOCX, OpenAPI schemas, and source files structurally, propagating section breadcrumbs and table headers automatically across spans (**$39/mo** Builder annual; **$0.25/1M** `Pro` tokens).

## Related Optimization Guides, Calculators & Benchmarks

- **[Gemini 2,048 Silent Truncation vs OpenAI 8,191 Token Limits](/optimize/gemini-2048-token-silent-truncation-vs-openai-8191/)**
- **[PDF Tables, 10-K Financial Grids & OpenAPI Vectorization](/optimize/pdf-tables-financial-grids-openapi-vectorization/)**
- **[OpenAI Embedding Cost Calculator](/tools/openai-embedding-cost-calculator/)**
- **[Audit Your Docs or GitHub Repo Free](/audit/)**

## Frequently Asked Questions

### Why should I pass token integer arrays instead of decoded text strings to OpenAI?

Passing cl100k_base integer arrays guarantees exact <=8191 token enforcement and avoids rare decode-reencode boundary expansions (+1 to +3 tokens) on split UTF-8 sequences.

### Does text-embedding-3-large fail or truncate silently above 8191 tokens?

OpenAI fails loudly with HTTP 400 for the whole batch, unlike Vertex gemini-embedding-001 which silently drops tokens past 2,048 by default.

---

## Zero-Install Model Context Protocol (MCP) & Keyless Agent Verification

```bash
claude mcp add --transport http voxell-forge https://api.voxell.ai/mcp/try
```

- Keyless Retrieval Bake-Off: `POST https://api.voxell.ai/api/v1/agent/bakeoff`
- Keyless Contradiction X-Ray: `POST https://api.voxell.ai/api/v1/agent/xray`
- Machine-Readable Pricing JSON: `https://voxell.ai/api/v1/agent/pricing.json`
- Full LLM Authority Map: `https://voxell.ai/llms-full.txt`
