Skip to content

Commit bfa036e

Browse files
steebchenclaude
andcommitted
feat(gateway): rate-limit the new /v1/ocr endpoint
Main added a /v1/ocr endpoint not covered by the org rate limiter. Add it to the per-path config (regular 300, dev 120, chat 30). OCR is available to dev/chat plans (it consumes their plan credits, no coding-plan block), so all three plan classes get a limit. Document the env vars and update the rate-limits docs page accordingly. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent befafd6 commit bfa036e

4 files changed

Lines changed: 14 additions & 1 deletion

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ TIMEOUT_MS=5000
8181
# GATEWAY_RATE_LIMIT_EMBEDDINGS_RPM=1200
8282
# GATEWAY_RATE_LIMIT_MODERATIONS_RPM=1200
8383
# GATEWAY_RATE_LIMIT_MODELS_RPM=1200
84+
# GATEWAY_RATE_LIMIT_OCR_RPM=300
8485
# GATEWAY_RATE_LIMIT_IMAGES_RPM=300
8586
# GATEWAY_RATE_LIMIT_AUDIO_SPEECH_RPM=300
8687
# GATEWAY_RATE_LIMIT_VIDEOS_RPM=120
@@ -93,6 +94,7 @@ TIMEOUT_MS=5000
9394
# GATEWAY_RATE_LIMIT_DEV_EMBEDDINGS_RPM=120
9495
# GATEWAY_RATE_LIMIT_DEV_MODERATIONS_RPM=120
9596
# GATEWAY_RATE_LIMIT_DEV_MODELS_RPM=120
97+
# GATEWAY_RATE_LIMIT_DEV_OCR_RPM=120
9698
# GATEWAY_RATE_LIMIT_DEV_IMAGES_RPM=120
9799
# GATEWAY_RATE_LIMIT_DEV_AUDIO_SPEECH_RPM=120
98100
# GATEWAY_RATE_LIMIT_DEV_VIDEOS_RPM=120
@@ -104,6 +106,7 @@ TIMEOUT_MS=5000
104106
# GATEWAY_RATE_LIMIT_CHATPLAN_EMBEDDINGS_RPM=120
105107
# GATEWAY_RATE_LIMIT_CHATPLAN_MODERATIONS_RPM=120
106108
# GATEWAY_RATE_LIMIT_CHATPLAN_MODELS_RPM=120
109+
# GATEWAY_RATE_LIMIT_CHATPLAN_OCR_RPM=30
107110
# GATEWAY_RATE_LIMIT_CHATPLAN_IMAGES_RPM=30
108111
# GATEWAY_RATE_LIMIT_CHATPLAN_AUDIO_SPEECH_RPM=30
109112
# GATEWAY_RATE_LIMIT_CHATPLAN_VIDEOS_RPM=12

apps/docs/content/resources/rate-limits.mdx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ The default limits (requests per minute, per organization) are:
2828
| Embeddings | `/v1/embeddings` | 1200 |
2929
| Moderations | `/v1/moderations` | 1200 |
3030
| Models | `/v1/models` | 1200 |
31+
| OCR | `/v1/ocr` | 300 |
3132
| Images | `/v1/images` | 300 |
3233
| Speech | `/v1/audio/speech` | 300 |
3334
| Videos | `/v1/videos` | 120 |
@@ -53,14 +54,15 @@ For example, an organization that has spent more than $10,000 gets a 4× multipl
5354

5455
Organizations on a **Dev plan** (also called devpass) or a **Chat plan** have their own, tighter per-endpoint limits and do not receive the spend-based multiplier.
5556

56-
Dev plans are inference-only and only cover **chat completions, messages, responses, and the models list**, each at a flat 120 requests-per-minute floor. The other endpoints (embeddings, moderations, images, speech, videos) are **not available** on Dev plans and are marked **** below.
57+
Dev plans are inference-only and only cover **chat completions, messages, responses, the models list, and OCR**, each at a flat 120 requests-per-minute floor. The other endpoints (embeddings, moderations, images, speech, videos) are **not available** on Dev plans and are marked **** below.
5758

5859
| Endpoint | Dev plan / min | Chat plan / min |
5960
| -------------------- | -------------- | --------------- |
6061
| Chat completions | 120 | 60 |
6162
| Messages (Anthropic) | 120 | 60 |
6263
| Responses | 120 | 60 |
6364
| Models | 120 | 120 |
65+
| OCR | 120 | 30 |
6466
| Embeddings || 120 |
6567
| Moderations || 120 |
6668
| Images || 30 |

apps/gateway/src/lib/org-rate-limit.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ describe("resolvePathRateLimit", () => {
8686
);
8787
expect(resolvePathRateLimit("/v1/models")?.key).toBe("models");
8888
expect(resolvePathRateLimit("/v1/messages")?.key).toBe("messages");
89+
expect(resolvePathRateLimit("/v1/ocr")?.key).toBe("ocr");
8990
});
9091

9192
it("matches sub-paths", () => {

apps/gateway/src/lib/org-rate-limit.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ export const PATH_RATE_LIMITS: readonly PathRateLimitConfig[] = [
9999
devDefaultRpm: 120,
100100
chatDefaultRpm: 120,
101101
},
102+
{
103+
key: "ocr",
104+
prefix: "/v1/ocr",
105+
defaultRpm: 300,
106+
devDefaultRpm: 120,
107+
chatDefaultRpm: 30,
108+
},
102109
{
103110
key: "images",
104111
prefix: "/v1/images",

0 commit comments

Comments
 (0)