Skip to content

Embeddings

Generate vector embeddings for text input.

Create Embedding

POST https://api.3xcoder.com/v1/embeddings

Creates an embedding vector representing the input text.

Request Body

ParameterTypeRequiredDescription
modelstringYesModel to use (e.g., text-embedding-3-small, text-embedding-3-large, text-embedding-ada-002)
inputstring/arrayYesText to embed. Can be a string or array of strings
encoding_formatstringNofloat or base64. Default: float
dimensionsintegerNoOutput dimensions (only for text-embedding-3-* models)

Response

json
{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [0.0023, -0.0091, 0.0152, ...],
      "index": 0
    }
  ],
  "model": "text-embedding-3-small",
  "usage": {
    "prompt_tokens": 8,
    "total_tokens": 8
  }
}

Examples

bash
curl https://api.3xcoder.com/v1/embeddings \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "model": "text-embedding-3-small",
    "input": "The quick brown fox jumps over the lazy dog"
  }'
python
from openai import OpenAI

client = OpenAI(
    api_key="your-api-key",
    base_url="https://api.3xcoder.com/v1"
)

response = client.embeddings.create(
    model="text-embedding-3-small",
    input="The quick brown fox jumps over the lazy dog"
)

print(response.data[0].embedding[:5])  # First 5 dimensions
javascript
const response = await fetch('https://api.3xcoder.com/v1/embeddings', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`
  },
  body: JSON.stringify({
    model: 'text-embedding-3-small',
    input: 'The quick brown fox jumps over the lazy dog'
  })
})

const data = await response.json()
console.log(data.data[0].embedding.length)
go
package main

import (
    "bytes"
    "encoding/json"
    "fmt"
    "io"
    "net/http"
)

func main() {
    body, _ := json.Marshal(map[string]interface{}{
        "model": "text-embedding-3-small",
        "input": "The quick brown fox jumps over the lazy dog",
    })

    req, _ := http.NewRequest("POST", "https://api.3xcoder.com/v1/embeddings",
        bytes.NewBuffer(body))
    req.Header.Set("Content-Type", "application/json")
    req.Header.Set("Authorization", "Bearer "+apiKey)

    resp, _ := http.DefaultClient.Do(req)
    defer resp.Body.Close()

    result, _ := io.ReadAll(resp.Body)
    fmt.Println(string(result))
}

Batch Embeddings

You can embed multiple texts in a single request by passing an array:

json
{
  "model": "text-embedding-3-small",
  "input": [
    "First document text",
    "Second document text",
    "Third document text"
  ]
}

The response will contain an embedding for each input text, ordered by index.

Reducing Dimensions

With text-embedding-3-* models, you can reduce the output dimensions to save storage:

json
{
  "model": "text-embedding-3-large",
  "input": "Sample text",
  "dimensions": 256
}

3xCoder — Unified AI API Endpoint