Model APIs
Embeddings and reranking
Build retrieval-augmented generation with embeddings and reranking, including input, dimensions and relevance scores.
Updated
/v1/embeddings/v1/rerankCreate text embeddings
POST /v1/embeddings accepts model and input, where input can be text or an array of strings. data[].embedding contains a vector and data[].index maps it to the input. Use an available embedding model with embeddings.create permission; a chat model is not automatically an embedding model.
curl --fail-with-body https://api.token4ai.cloud/v1/embeddings \
-H "Authorization: Bearer $TOKEN4AI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_MODEL_ID",
"input": [
"A unified model gateway",
"Cloud agent task execution"
]
}'Keep dimensions and indexes consistent
Keep the embedding model, vector dimensions and normalization consistent within an index. Switching models typically requires re-embedding documents; do not mix a new query vector with an old index. Chunk long documents and retain original-source references for each chunk.
Rerank candidate documents
POST /v1/rerank orders existing candidates; it does not replace retrieval or vector storage. query must be nonempty and documents must be a nonempty array of strings or objects containing text. top_n is a positive integer and return_documents requests document text in the result.
curl --fail-with-body https://api.token4ai.cloud/v1/rerank \
-H "Authorization: Bearer $TOKEN4AI_API_KEY" \
-H "Content-Type: application/json" \
--data '{
"model": "YOUR_MODEL_ID",
"query": "How can I run an agent in the cloud?",
"documents": [
"Configure a cloud agent in Vega.",
"Embedding vectors support semantic search."
],
"top_n": 1,
"return_documents": true
}'