Embeddings

Turn text into vectors with the OpenAI-compatible endpoint.

POST https://api.topbilling.in/v1/embeddings accepts the OpenAI Embeddings request body, so the official SDK works with only its base URL changed. Use a model whose capabilities include embeddings.

POST /v1/embeddings
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["TB_API_KEY"], base_url="https://api.topbilling.in/v1")

result = client.embeddings.create(
    model="<embedding-model-id>",
    input=["Refund policy for annual plans", "How do I rotate an API key?"],
)
print(len(result.data), len(result.data[0].embedding))

Input

  • input is a string or an array of strings. Empty strings are rejected.
  • Pre-tokenised input (arrays of token ids) is not supported: send text. It returns 400 naming input.
  • encoding_format is float (default) or base64. dimensions, when sent, must be a positive integer.

Response

json
{
  "object": "list",
  "data": [{"object": "embedding", "index": 0, "embedding": [0.0123, -0.0456, ...]}],
  "model": "<embedding-model-id>",
  "usage": {"prompt_tokens": 12, "total_tokens": 12}
}

Billing

Embeddings run the same money path as chat: an upper bound is reserved, then settled on the input tokens the model reported. Fields the endpoint does not use are ignored and counted in the tb-dropped-hints response header. The key needs the chat:write scope.