Does the Aggregator Proxy Embeddings? Calling /embeddings Through an OpenAI-Compatible Client
This article explains how to call the /embeddings endpoint through an OpenAI-compatible client when using an LLM API aggregator that proxies multiple model providers. It covers the basics of the embeddings API, how the proxy forwards requests, and practical steps for configuration and testing.
What Is the Embeddings Endpoint?
The /embeddings endpoint is a standard part of the OpenAI API specification. It accepts text input and returns a vector representation (embedding) that captures semantic meaning. Embeddings are widely used for search, clustering, recommendation, and retrieval-augmented generation (RAG).
Most LLM API aggregators that offer OpenAI-compatible interfaces also support the embeddings endpoint, either natively or by proxying to an upstream provider. This allows you to use the same API key and base URL for both chat completions and embeddings.
How the Aggregator Proxies Embeddings
When you send a request to /embeddings through the aggregator, the following happens:
- The aggregator receives your request, including the
modelparameter and the input text. - It checks your API key and account balance (or credit).
- It routes the request to the appropriate upstream provider that serves the requested embedding model.
- The provider returns the embedding vector to the aggregator, which then forwards it back to you.
- Your usage is billed according to the aggregator's pricing (official price × 1.3).
Note: The aggregator does not modify the embedding vectors; it simply proxies them. The model name must match a supported embedding model. If you are unsure which embedding models are available, check the aggregator's documentation or model list endpoint.
Setting Up an OpenAI-Compatible Client
To call the embeddings endpoint through the aggregator, configure your client with the aggregator's base URL and your API key. For example, using the OpenAI Python SDK:
from openai import OpenAI
client = OpenAI(
api_key="YOUR_AGGREGATOR_API_KEY",
base_url="https://api.aggregator.example/v1" # replace with actual base URL
)
response = client.embeddings.create(
model="text-embedding-3-small", # use a model supported by the aggregator
input="The quick brown fox jumps over the lazy dog"
)
print(response.data[0].embedding)
Replace the base_url with the aggregator's documented endpoint. The model parameter must be a valid embedding model name accepted by the aggregator.
Common Pitfalls and Tips
- Model name mismatch: Ensure the model name is exactly as supported by the aggregator. Some aggregators prefix model names with a provider identifier (e.g.,
openai/text-embedding-3-small). - Input format: The
/embeddingsendpoint accepts a string or an array of strings. Batch your inputs to reduce overhead, but stay within the provider's limits. - Error handling: If the aggregator returns an error, check that your API key has sufficient credit and that the model is available. The error format is usually OpenAI-compatible.
- Rate limits: The aggregator may impose its own rate limits on top of upstream provider limits. Implement retries with backoff for robustness.
- Vector dimensions: Different embedding models produce vectors of different sizes. Ensure your downstream applications (e.g., vector databases) are configured accordingly.
Billing for Embeddings
Embeddings calls are billed like other API calls: you pay the official price × 1.3. If you are a key contributor, you receive credit at official price × 1.1 (or × 1.2 for premium) in USDC. This applies to embeddings usage as well, provided the aggregator includes embeddings in its billable services.
Testing Your Setup
A quick way to verify that embeddings work through the aggregator is to compare the output for two similar sentences. The cosine similarity between their vectors should be high. You can also check the usage field in the response to see token counts.
import numpy as np
resp = client.embeddings.create(
model="text-embedding-3-small",
input=["The cat sat on the mat", "A cat is sitting on a mat"]
)
vecs = [d.embedding for d in resp.data]
sim = np.dot(vecs[0], vecs[1]) / (np.linalg.norm(vecs[0]) * np.linalg.norm(vecs[1]))
print(f"Similarity: {sim:.3f}")
If the similarity score is reasonably high (e.g., above 0.8), your setup is likely correct.
Conclusion
Yes, most LLM API aggregators that provide OpenAI-compatible endpoints also proxy the /embeddings endpoint. By configuring your client with the aggregator's base URL and a supported model name, you can generate embeddings without changing your existing code. Remember to monitor your usage and ensure your API key has sufficient credit. For specific model availability and endpoint details, consult the aggregator's official documentation.