Browse documentation

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/embeddings

Requests 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

ParameterTypeRequiredDefaultDescription
modelstringYes—Model ID (e.g. text-embedding-3-small, text-embedding-3-large).
inputstring or string[]Yes—Text string or array of strings to embed.
dimensionsintegerNo—Output embedding dimensions (supported on text-embedding-3-*).
encoding_formatstringNofloatFormat: float or base64.
userstringNo—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 StatusError CodeReason
400 Bad Requestinvalid_requestInput exceeds token ceiling or invalid dimensions.
400 Bad Requestguardrail_blockedContent safety or injection policy violation.
401 Unauthorizedinvalid_api_keyVirtual key missing, expired, or invalid.
402 Payment Requiredinsufficient_creditsOrganization balance insufficient for token hold.
404 Not Foundmodel_not_foundModel unrecognized or disabled.
429 Too Many Requestsrate_limit_exceededRPM/TPM limit exceeded; check x-nr-limit-source.
POST
/v1/embeddings

Authorization

NRouterApiKey
AuthorizationBearer <token>

Your nRouter virtual key (sk-nrouter-…). Sent as Authorization: Bearer sk-nrouter-….

In: header

Header Parameters

x-nr-tags?string

Custom spend and attribution tags (comma-separated key=value pairs)

x-nr-mcp-server?string

Target MCP server ID when routing MCP tool calls or prompts through the gateway

x-nr-client-language?string

Caller SDK runtime language identification (e.g. typescript, python, rust, go)

x-nr-session-id?string

Caller session identifier allowed at edge for grouping related client turns

x-nr-trace?string

Inbound trace detail level override for request lifecycle spans

Value in

  • "off"
  • "stages"
  • "verbose"
x-nr-trace-stages?string

Inbound stage-level trace emission override

Value in

  • "off"
  • "stages"
  • "verbose"
x-nr-trace-id?string

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  }}
Was this page helpful?