Full Issue Details:
When sending embedding requests to the text-embedding-3-large
endpoint, I am encountering a RateLimitError
for exceeding the 1,000,000 TPM limit for a Tier 2 account. Despite calculating token usage with tiktoken
(cl100k_base
tokenizer) and keeping the total tokens exactly at 1,000,000, the API returns an error indicating a higher token count (1,095,015).
Error Message via Python API:
openai.RateLimitError: Error code: 429 - {'error': {'message': 'Request too large for text-embedding-3-large in organization REDACTED on tokens per min (TPM): Limit 1000000, Requested 1095015. The input or output tokens must be reduced in order to run successfully. Visit https://platform.openai.com/account/rate-limits to learn more.', 'type': 'tokens', 'param': None, 'code': 'rate_limit_exceeded'}}
Error Message via Curl:
{
"error": {
"message": "Request too large for text-embedding-3-large in organization REDACTED on tokens per min (TPM): Limit 1000000, Requested 1095015. The input or output tokens must be reduced in order to run successfully. Visit https://platform.openai.com/account/rate-limits to learn more.",
"type": "tokens",
"param": null,
"code": "rate_limit_exceeded"
}
}
Steps to Reproduce:
- Repo: I can’t add a link but its at on github at jcourson8/openai_token_count_error_replication.git (Requires Tier 2 with a 1,000,000 TPM limit)
- Code:
- Embedding request:
client.embeddings.create(model="text-embedding-3-large", input=documents)
- Token count function:
def openai_token_count(string: str) -> int: encoding = tiktoken.get_encoding("cl100k_base") num_tokens = len(encoding.encode(string, disallowed_special=())) return num_tokens
- Token count for documents:
sum(openai_token_count(doc) for doc in documents)
- Embedding request:
- Document Info:
documents
is aList[str]
with length 15,758.- Maximum individual document token count: 340 (well below the 8k limit).
Issue: Despite calculated tokens totaling 1,000,000, the API reports a request of 1,095,015 tokens.
Environment:
- OS: macOS
- Python Version: 3.10.11
- OpenAI Library Version: 1.34.0