OpenAI embeddings cost per token
Quick answer
OpenAI charges for embeddings based on input tokens, typically at a rate of $0.0004 per 1,000 tokens for the
text-embedding-3-small model. This means each token costs approximately $0.0000004, so you can estimate your usage cost by counting tokens sent to the embeddings endpoint.PREREQUISITES
Python 3.8+OpenAI API key (free tier works)pip install openai>=1.0
Setup
Install the official OpenAI Python SDK and set your API key as an environment variable to access the embeddings API.
pip install openai>=1.0 Step by step
Use the OpenAI SDK to create embeddings and understand token usage for cost estimation.
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
text = "OpenAI embeddings cost per token"
response = client.embeddings.create(
model="text-embedding-3-small",
input=text
)
embedding_vector = response.data[0].embedding
print(f"Embedding vector length: {len(embedding_vector)}")
# Example token count and cost calculation
# Assume token count for input text is 8 tokens
tokens_used = 8
cost_per_1000_tokens = 0.0004 # USD
cost = (tokens_used / 1000) * cost_per_1000_tokens
print(f"Estimated cost for {tokens_used} tokens: ${cost:.8f}") output
Embedding vector length: 384 Estimated cost for 8 tokens: $0.00000320
Common variations
You can use different embedding models with varying costs and token limits. Async calls and batch inputs are also supported for efficiency.
import asyncio
import os
from openai import OpenAI
client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])
async def create_embeddings_async(texts):
response = await client.embeddings.acreate(
model="text-embedding-3-small",
input=texts
)
return response.data
texts = ["Hello world", "OpenAI embeddings"]
embeddings = asyncio.run(create_embeddings_async(texts))
for i, emb in enumerate(embeddings):
print(f"Embedding {i} length: {len(emb.embedding)}") output
Embedding 0 length: 384 Embedding 1 length: 384
Troubleshooting
- If you get authentication errors, verify your
OPENAI_API_KEYenvironment variable is set correctly. - For token counting, use OpenAI's tokenizer tools or third-party libraries to avoid underestimating costs.
- Check model availability and pricing updates on OpenAI's official pricing page.
Key Takeaways
- OpenAI embeddings cost $0.0004 per 1,000 tokens for
text-embedding-3-smallas of 2026-04. - Calculate cost by counting input tokens and multiplying by the per-token rate.
- Use official SDK methods to create embeddings and monitor token usage for budgeting.