Embeddings
Creates an embedding vector representing the input text.
POST /v1/inference/embeddings
Get vector embeddings for text (OpenAI-compatible).
Request Headers
Content-Type: "application/json"
Authorization: Bearer GRAVIXLAYER_API_KEY
Example Usage
- cURL
- Python
- JavaScript
embeddings.sh
curl https://api.gravixlayer.com/v1/inference/embeddings \
-H "Authorization: Bearer $GRAVIXLAYER_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"input": "Why is the sky blue?",
"model": "llama3.1:8b"
}'
embeddings.py
import os
import json
from openai import OpenAI
client = OpenAI(
base_url="https://api.gravixlayer.com/v1/inference",
api_key=os.environ.get("GRAVIXLAYER_API_KEY"),
)
embedding = client.embeddings.create(
model="llama3.1:8b",
input="Why is the sky blue?",
)
print(json.dumps(embedding.model_dump(), indent=2))
embeddings.js
import OpenAI from "openai";
const openai = new OpenAI({
apiKey: process.env.GRAVIXLAYER_API_KEY,
baseURL: "https://api.gravixlayer.com/v1/inference"
});
async function main() {
const embedding = await openai.embeddings.create({
model: "llama3.1:8b",
input: "Why is the sky blue?",
encoding_format: "float",
});
console.log(JSON.stringify(embedding, null, 2));
}
main();
Response
The API returns a JSON response with the following structure:
{
"object": "list",
"data": [
{
"object": "embedding",
"embedding": [
0.0023064255,
-0.009327292,
-0.0028842222,
"... (1536 floats total for text-embedding-ada-002)"
],
"index": 0
}
],
"model": "llama3.1:8b",
"usage": {
"prompt_tokens": 5,
"total_tokens": 5
}
}