> ## Documentation Index
> Fetch the complete documentation index at: https://student-213fb9fc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Embeddings (OpenAI)

> Generate text embeddings via the OpenAI-compatible endpoint

## Overview

Generate vector embeddings for a given input text, fully compatible with the OpenAI `/v1/embeddings` format. Use with tools like LangChain, LlamaIndex, or any RAG pipeline.

## Request

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token: `Bearer YOUR_API_KEY`
</ParamField>

### Body

<ParamField body="model" type="string" required>
  Model to use. Recommended embedding models: `gemma3:4b`, `gemma3:12b`.
</ParamField>

<ParamField body="input" type="string or array" required>
  Text to embed. Can be a single string or array of strings for batch embedding.
</ParamField>

<ParamField body="encoding_format" type="string" default="float">
  Format for the returned embeddings. Options: `"float"` or `"base64"`.
</ParamField>

***

## Response

<ResponseField name="object" type="string">
  `"list"`
</ResponseField>

<ResponseField name="data" type="array">
  Array of embedding objects:

  * `object` — `"embedding"`
  * `index` — index of the input
  * `embedding` — the vector as an array of floats
</ResponseField>

<ResponseField name="model" type="string">
  The model used.
</ResponseField>

<ResponseField name="usage" type="object">
  Token counts: `prompt_tokens`, `total_tokens`.
</ResponseField>

***

## Examples

<CodeGroup>
  ```python Single Embedding theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.ajstudioz.co.in/v1",
      api_key="YOUR_API_KEY"
  )

  response = client.embeddings.create(
      model="gemma3:4b",
      input="AJ STUDIOZ provides cloud AI inference at scale"
  )

  embedding = response.data[0].embedding
  print(f"Dimensions: {len(embedding)}")
  ```

  ```python Batch Embeddings theme={null}
  from openai import OpenAI

  client = OpenAI(
      base_url="https://api.ajstudioz.co.in/v1",
      api_key="YOUR_API_KEY"
  )

  texts = [
      "The quick brown fox",
      "Machine learning is transforming industries",
      "Cloud computing enables scalable AI"
  ]

  response = client.embeddings.create(
      model="gemma3:4b",
      input=texts
  )

  for item in response.data:
      print(f"[{item.index}] dim={len(item.embedding)} first5={item.embedding[:5]}")
  ```

  ```python RAG Pipeline theme={null}
  from openai import OpenAI
  import numpy as np

  client = OpenAI(
      base_url="https://api.ajstudioz.co.in/v1",
      api_key="YOUR_API_KEY"
  )

  # Embed documents
  docs = [
      "AJ STUDIOZ supports Ollama and OpenAI APIs.",
      "Models available include Gemma, Qwen, and DeepSeek.",
      "You can use function calling with supported models.",
  ]
  doc_embeddings = [
      client.embeddings.create(model="gemma3:4b", input=d).data[0].embedding
      for d in docs
  ]

  # Embed query
  query = "What APIs does AJ STUDIOZ support?"
  query_embedding = client.embeddings.create(
      model="gemma3:4b", input=query
  ).data[0].embedding

  # Find most similar
  def cosine_sim(a, b):
      a, b = np.array(a), np.array(b)
      return np.dot(a, b) / (np.linalg.norm(a) * np.linalg.norm(b))

  scores = [cosine_sim(query_embedding, de) for de in doc_embeddings]
  best_idx = np.argmax(scores)
  print(f"Most relevant: {docs[best_idx]} (score: {scores[best_idx]:.4f})")
  ```

  ```bash cURL theme={null}
  curl https://api.ajstudioz.co.in/v1/embeddings \
    -H "Authorization: Bearer YOUR_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "model": "gemma3:4b",
      "input": "The sky is blue because of Rayleigh scattering"
    }'
  ```
</CodeGroup>

<ResponseExample>
  ```json Response theme={null}
  {
    "object": "list",
    "data": [
      {
        "object": "embedding",
        "index": 0,
        "embedding": [0.1234, -0.5678, 0.9012, 0.3456, -0.7890, "..."]
      }
    ],
    "model": "gemma3:4b",
    "usage": {
      "prompt_tokens": 10,
      "total_tokens": 10
    }
  }
  ```
</ResponseExample>
