Embeddings
Generate high-dimensional vector embeddings for text with nRouter. Compatible with OpenAI embeddings endpoints for semantic search, clustering, and RAG.
The /v1/embeddings endpoint generates numerical vector representations for semantic search, retrieval-augmented generation (RAG), and clustering. It routes across OpenAI, Cohere, Voyage, and Google Vertex AI at exact provider token rates with zero markup.
POST https://api.nrouter.ai/v1/embeddingsRequests run preflight as Chat Completions: key validation, rate limits, and content inspection (x-nr-guardrails: blocked returns HTTP 400 with zero spend). Input tokens reserve credits that settle upon provider return.
Request Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
model | string | Yes | — | Model ID (e.g. text-embedding-3-small, text-embedding-3-large). |
input | string or string[] | Yes | — | Text string or array of strings to embed. |
dimensions | integer | No | — | Output embedding dimensions (supported on text-embedding-3-*). |
encoding_format | string | No | float | Format: float or base64. |
user | string | No | — | Unique end-user identifier for abuse monitoring. |
Response
{
"object": "list",
"data": [
{
"object": "embedding",
"index": 0,
"embedding": [-0.0069, -0.0053, 0.0084]
}
],
"model": "text-embedding-3-small",
"usage": { "prompt_tokens": 8, "total_tokens": 8 }
}Examples
curl -X POST https://api.nrouter.ai/v1/embeddings \
-H "Authorization: Bearer $NROUTER_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"text-embedding-3-small","input":"Vector embedding search."}'Headers & Errors
Required request headers: Authorization: Bearer sk-nrouter-... and Content-Type: application/json. Response telemetry includes x-nr-request-id, x-nr-latency-ms, x-nr-request-cost, x-nr-model. See Chat Completions.
| HTTP Status | Error Code | Reason |
|---|---|---|
| 400 Bad Request | invalid_request | Input exceeds token ceiling or invalid dimensions. |
| 400 Bad Request | guardrail_blocked | Content safety or injection policy violation. |
| 401 Unauthorized | invalid_api_key | Virtual key missing, expired, or invalid. |
| 402 Payment Required | insufficient_credits | Organization balance insufficient for token hold. |
| 404 Not Found | model_not_found | Model unrecognized or disabled. |
| 429 Too Many Requests | rate_limit_exceeded | RPM/TPM limit exceeded; check x-nr-limit-source. |
Authorization
NRouterApiKey Your nRouter virtual key (sk-nrouter-…). Sent as Authorization: Bearer sk-nrouter-….
In: header
Header Parameters
Target MCP server ID when routing MCP tool calls or prompts through the gateway
Caller SDK runtime language identification (e.g. typescript, python, rust, go)
Caller session identifier allowed at edge for grouping related client turns
Inbound trace detail level override for request lifecycle spans
Value in
- "off"
- "stages"
- "verbose"
Inbound stage-level trace emission override
Value in
- "off"
- "stages"
- "verbose"
Accepted so a client sending it is not refused; the value is not recorded and not propagated. Every response carries the gateway's own trace ID in this header, never the one sent.
Request Body
application/json
TypeScript Definitions
Use the request body type in TypeScript.
Response Body
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
application/json
curl -X POST "https://example.com/v1/embeddings" \ -H "Content-Type: application/json" \ -d '{ "model": "text-embedding-3-small", "input": "The quick brown fox jumps over the lazy dog." }'{ "object": "list", "model": "text-embedding-3-small", "data": [ { "object": "embedding", "index": 0, "embedding": [ 0.0023, -0.009, 0.015 ] } ], "usage": { "prompt_tokens": 5, "total_tokens": 5 }}