Embeddings
Generate high-quality vector embeddings for text using the Gravix Layer API. This endpoint is compatible with OpenAI's embedding API and supports seamless integration in Python and JavaScript.
Quickstart
Get started by calling the embeddings endpoint with your API key and model of choice.
Endpoint
POST /v1/inference/embeddings
Request Headers
Content-Type: "application/json"
Authorization: Bearer GRAVIXLAYER_API_KEY
Example Usage
- cURL
- Python - OpenAI
- Python - Gravix SDK
- JavaScript
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": "meta-llama/llama-3.1-8b-instruct"
}'
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="meta-llama/llama-3.1-8b-instruct",
input="Why is the sky blue?",
)
print(json.dumps(embedding.model_dump(), indent=2))
import os
from gravixlayer import GravixLayer
# Make sure to export your API key in the environment
# export GRAVIXLAYER_API_KEY=your_api_key_here
client = GravixLayer()
embedding = client.embeddings.create(
model="meta-llama/llama-3.1-8b-instruct",
input="Why is the sky blue?",
)
import json
print(json.dumps(embedding.model_dump(), indent=2))
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: "meta-llama/llama-3.1-8b-instruct",
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": "meta-llama/llama-3.1-8b-instruct",
"usage": {
"prompt_tokens": 5,
"total_tokens": 5
}
}