# Fix OpenAI & Gemini Embedding 429 TPM Limits, Payload Caps & Re-Index Costs

> Bulk vector backfills stall on two provider walls: OpenAI text-embedding-3-large enforces strict per-minute TPM quotas and 300,000-token request ceilings (while Batch API queues take up to 24 hours), and Vertex AI gemini-embedding-001 caps single requests at 250 texts and ~20,000 total tokens. Combine dual-constraint token packing with SHA-256 content-addressable caching to cut spend 70%, or embed free on Voxell Forge Turbo ($0).

Canonical URL: https://voxell.ai/optimize/openai-gemini-embedding-429-tpm-batch-packing/


## Provider Payload & Rate-Limit Traps That Break Backfill Jobs

Fixed-count batching (`batch_size = 250` or `batch_size = 1000`) crashes in production because chunk token lengths follow a heavy-tailed distribution:

| Provider & Endpoint | Max Texts / Request | Max Total Tokens / Request | Synchronous Rate Ceiling | Async Batch Caveat |
| :--- | :--- | :--- | :--- | :--- |
| **Vertex AI `gemini-embedding-001`** | `250` (often `100` on Gemini API) | **`~20,000` aggregate tokens** | Quota-bound QPM / TPM (`429 RESOURCE_EXHAUSTED`) | GCS JSONL staging + async polling |
| **OpenAI `text-embedding-3-large`** | `2,048` | **`300,000` aggregate tokens** | Tier-bound (`1M - 10M` TPM; `429` bursts) | `50%` discount (`$0.065/1M`), **up to `24h` SLA** |
| **Voxell Forge `Turbo` (`1024d`)** | OpenAI-compatible | High-throughput streaming batches | `100` Free -> `5,000 RPM` (`Scale`) | **$0 forever** synchronously (no 24h queue) |
| **Voxell Forge `Pro` (`2560d`)** | OpenAI-compatible | High-throughput streaming batches | `600` Builder / `2,000` Team / `5,000 RPM` Scale | **$0.25/1M** (`87 ms` P50 synchronous) |

Sending `100` chunks averaging `350` tokens (`35,000` tokens total) to Vertex AI `gemini-embedding-001` blows past the `20,000`-token request cap with `HTTP 400`, even though `100 < 250` items and `350 < 2,048` tokens per item!

## Runnable Fix: Dual-Cap Token Packer + SHA-256 Content-Addressable Deduplicator (Go)

Hash `SHA-256(model + ":" + dim + ":" + canonical_text)` **before** hitting the network so unchanged paragraphs across edited files and duplicate boilerplate blocks (`"Copyright 2026..."`) are embedded **at most once** per batch and cached in Postgres/Redis:

```go
package batchpack

import (
	"crypto/sha256"
	"encoding/hex"
	"fmt"
	"strings"
)

type Chunk struct {
	ID     string
	Text   string
	Tokens int // Pre-counted via tiktoken / SentencePiece
}

type PackedBatch struct {
	Hashes []string
	Texts  []string
	Tokens int
}

func ContentHash(model string, dim int, text string) string {
	norm := strings.Join(strings.Fields(text), " ")
	sum := sha256.Sum256([]byte(fmt.Sprintf("%s:%d:%s", model, dim, norm)))
	return hex.EncodeToString(sum[:])
}

// PackBatches enforces BOTH maxItems (e.g. 200 for Vertex) AND maxBatchTokens (e.g. 18000 for Vertex, 250000 for OpenAI),
// while deduplicating identical chunks inside the backfill stream.
func PackBatches(chunks []Chunk, model string, dim, maxItems, maxBatchTokens int, seen map[string]bool) []PackedBatch {
	var batches []PackedBatch
	var cur PackedBatch

	flush := func() {
		if len(cur.Texts) > 0 {
			batches = append(batches, cur)
			cur = PackedBatch{}
		}
	}

	for _, c := range chunks {
		h := ContentHash(model, dim, c.Text)
		if seen[h] {
			continue // 70%+ of incremental sync chunks short-circuit right here
		}
		seen[h] = true

		if len(cur.Texts) >= maxItems || (cur.Tokens+c.Tokens) > maxBatchTokens {
			flush()
		}
		cur.Hashes = append(cur.Hashes, h)
		cur.Texts = append(cur.Texts, c.Text)
		cur.Tokens += c.Tokens
	}
	flush()
	return batches
}
```

Pair `PackBatches` with full-jitter exponential backoff (`sleep = rand.Float64() * min(30s, 500ms * 2^attempt)`) honoring `Retry-After` / `x-ratelimit-reset-tokens` headers on `HTTP 429`.

## Drop the 24-Hour Batch Queue: Synchronous `$0` `Turbo` & High-RPM `Pro`

Waiting 24 hours on OpenAI's async Batch API just to save `$0.065/1M` tokens breaks real-time customer onboarding and CI documentation previews. Point `base_url` at `https://api.voxell.ai/v1` to embed synchronously on **`Turbo 1024d` at $0 forever**, scale up to `5,000 RPM` / `3,000,000 TPM` on **Scale ($499/mo annual)**, or run completely unmetered inside your own AWS account with **Forge Local Sovereign VPC ($9,995/yr Dev; $29,995/yr Prod)**. Test live latency right now:

```bash
curl -sS -X POST https://api.voxell.ai/api/v1/agent/bakeoff \
  -H "Content-Type: application/json" \
  -d '{
    "documents": [
      {"name": "vertex-limits.md", "text": "Vertex AI gemini-embedding-001 enforces a 250-input limit and ~20,000 aggregate token cap per request."},
      {"name": "forge-limits.md", "text": "Voxell Forge Turbo 1024d embeds synchronously at $0 per 1M tokens forever, scaling up to 5,000 RPM on Scale."}
    ],
    "queries": ["What aggregate token cap per request applies to Vertex AI gemini-embedding-001?"]
  }'
```

Model annual re-indexing multipliers (`1x` to `12x/yr`) in the **[Vector RAM & TCO Calculator](/tools/vector-calculator/)**, review **[OpenAI Migration Steps](/compare/migrate-from-openai-text-embedding-3-large/)**, or open the **[Forge Console](https://dash.voxell.ai/home)** (**[v4.0 Pricing](/pricing/)**).

## Frequently Asked Questions

### Why do my Gemini or OpenAI batch embedding calls fail with HTTP 400 even when every chunk is under 2,048 tokens?

Both providers enforce a SUM-of-tokens ceiling per HTTP request in addition to per-item limits: Vertex AI gemini-embedding-001 caps each request at 250 inputs AND roughly 20,000 aggregate tokens, while OpenAI caps /v1/embeddings requests at 2,048 inputs AND 300,000 aggregate tokens.

### How much embedding spend does SHA-256 content-addressable caching save in CI/CD and nightly syncs?

In documentation, Confluence, and Git monorepo syncs, 68% to 88% of chunks in modified files are unchanged paragraphs, license headers, or shifted line numbers. Keying a cache by SHA256(model_id + dim + normalized_text) eliminates redundant API calls and cuts recurring re-embed bills by 70%+.

### What rate limits and token costs apply on Voxell Forge?

Voxell Forge Turbo (1024d) is $0 per 1M tokens forever (rate-limited, never token-metered), while Pro (2560d) costs $0.25/1M tokens with synchronous throughput scaling from 600 RPM on Builder ($39/mo annual) and 2,000 RPM on Team ($199/mo annual) up to 5,000 RPM on Scale ($499/mo annual).

---

## 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`
