# An embeddings API for RAG: one key, two vector sizes

> Generate vector embeddings for RAG with an OpenAI-compatible API, choosing between 1536 and 3072 dimensions under one unified key.

**You can generate vector embeddings for retrieval-augmented generation (RAG) using thelastapi's OpenAI-compatible endpoint at `/v1/ai/embeddings` with a single API key.** It provides two stable embedding models: `vibiz/embed` (1536 dimensions at $0.02 per million tokens) and `vibiz/embed-large` (3072 dimensions at $0.13 per million tokens). You can batch up to 2,048 text inputs per request using standard client libraries, keep your embedding costs on the same prepaid balance as your chat completions, and never manage separate vendor credentials.

Retrieval-augmented generation pairs an information retrieval step with a language model prompt. Before an AI assistant answers a question about your internal documentation, user manuals, or product listings, you convert those documents into vector representations and store them in a database. When a user asks a query, you embed their question with the same model, find the closest matching vectors, and feed the retrieved passages to a generation model like Claude, GPT, or Gemini.

Managing this workflow often forces teams to configure separate credentials for embedding providers, vector generation endpoints, and generation models. thelastapi eliminates that fragmentation by putting embeddings and generation behind one OpenAI-compatible route.

## Choosing between 1536 and 3072 dimensions

When you build an index for RAG, your choice of vector dimensions directly dictates database storage requirements, indexing performance, and semantic detail. thelastapi provides two designated models backed by OpenAI's third-generation embedding architecture:

| thelastapi model | Underlying lab model | Output vector size | Price per million tokens | Maximum batch size |
| --- | --- | --- | --- | --- |
| `vibiz/embed` | `text-embedding-3-small` (OpenAI) | 1,536 dimensions | $0.02 | 2,048 inputs |
| `vibiz/embed-large` | `text-embedding-3-large` (OpenAI) | 3,072 dimensions | $0.13 | 2,048 inputs |

Picking between these models depends on your dataset size and accuracy requirements:

- **Use `vibiz/embed` (1,536 dimensions)** for high-volume knowledge bases, search over short snippets, and cost-sensitive applications. At $0.02 per million tokens, you can index roughly 750,000 words of text for two cents. The smaller vector size keeps your database index compact and fast to scan during similarity queries.
- **Use `vibiz/embed-large` (3,072 dimensions)** when your corpus involves subtle domain terminology, multi-lingual knowledge graphs, or complex technical reasoning where fine-grained semantic distance makes a demonstrable difference in retrieval accuracy.

Once you embed a document collection and store its vectors in a database table, **you cannot change the model or dimension without re-indexing all documents**. Mixing 1,536-dimension vectors with 3,072-dimension vectors in the same similarity comparison fails mathematically. Pick one model for a specific collection and stay consistent across both indexing and querying.

If you have a Google account, you can also connect your own key using `vibiz ai keys set google` to route Google models through the platform. By default, embeddings on your own Google key are disabled to prevent accidentally querying an existing index with mismatched vectors. You can enable them for a fresh index via `PATCH /v1/ai-keys/google` with `{"use_for": ["llm", "embeddings"]}`.

## Setting up your client with one key

Every project on thelastapi includes access to the unified AI gateway. You can provision a new application or configure an existing project from the terminal:

```bash
vibiz init "Acme Docs RAG" --resources ai
vibiz dev
```

The `vibiz dev` command provisions your development environment and writes local variables to `.env.development.local`. This exports `VIBIZ_AI_BASE_URL` and `VIBIZ_AI_API_KEY`, as well as their common aliases `OPENAI_BASE_URL` and `OPENAI_API_KEY`.

Because the gateway uses the OpenAI schema, you can point standard community SDKs directly at the base URL. If your application uses the `@vibiz/app` package, you can pass `vibiz.ai` directly to your client without manually reading environment variable names:

```ts
import { vibiz } from '@vibiz/app';
import OpenAI from 'openai';

// Automatically uses the project's gateway URL and key
const openai = new OpenAI(vibiz.ai);
```

For more details on managing access levels across automated environments and production deployments, read about [Keys and environments](https://thelastapi.dev/docs/keys) and see how to [access multiple AI models with a single API](https://thelastapi.dev/blog/access-multiple-ai-models-single-api).

## How to generate embeddings in batch

When ingesting documents into your RAG pipeline, sending texts one at a time introduces unnecessary HTTP round trips. thelastapi accepts arrays of up to 2,048 strings per request on `POST /v1/ai/embeddings`.

Here is an example in TypeScript that embeds an array of text chunks using `vibiz/embed`:

```ts
import OpenAI from 'openai';

const openai = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

async function embedChunks(chunks: string[]) {
  const response = await openai.embeddings.create({
    model: 'vibiz/embed',
    input: chunks,
  });

  // Extract the 1536-dimensional float arrays
  const vectors = response.data.map((item) => item.embedding);
  console.log(`Generated ${vectors.length} vectors.`);
  console.log(`Vector dimension: ${vectors[0].length}`);

  return vectors;
}

const sampleDocs = [
  'Our refund policy allows returns within 30 days of purchase.',
  'Enterprise subscriptions include 24/7 dedicated telephone support.',
  'To reset your password, visit the settings panel and confirm your email.',
];

await embedChunks(sampleDocs);
```

You can also call the endpoint directly with standard HTTP clients from any language:

```bash
curl https://thelastapi.dev/v1/ai/embeddings \
  -H "Authorization: Bearer $VIBIZ_AI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "vibiz/embed",
    "input": ["First document chunk", "Second document chunk"]
  }'
```

Every response returns the generated vector objects and records token consumption on your account usage ledger.

## Connecting retrieval to generation in a RAG pipeline

The main advantage of using thelastapi for RAG is unifying retrieval and synthesis under one configuration. After retrieving relevant passages from your database, you send the context and user query to any chat model supported on the platform—such as `vibiz/fast` (GPT-6 Luna), `vibiz/smart` (Claude Sonnet 5.5), or `vibiz/balanced` (Gemini 3.8 Flash).

You do not need to register a separate key for Anthropic or Google to generate the answer. To see how chat model switching works, review [One API key for GPT, Claude and Gemini: how a unified AI API works](https://thelastapi.dev/blog/one-api-key-gpt-claude-gemini) and our guide on [OpenAI-compatible API for Claude and Gemini: change one base URL](https://thelastapi.dev/blog/openai-compatible-api-claude-gemini).

Here is a complete script demonstrating the RAG bridge: embedding a query, pretending to match documents, and generating an answer with a Claude-backed tier:

```ts
import OpenAI from 'openai';

const client = new OpenAI({
  baseURL: process.env.VIBIZ_AI_BASE_URL,
  apiKey: process.env.VIBIZ_AI_API_KEY,
});

async function answerQuestion(userQuery: string) {
  // 1. Embed the incoming user query with the same model used during ingestion
  const queryEmbeddingRes = await client.embeddings.create({
    model: 'vibiz/embed',
    input: userQuery,
  });
  const queryVector = queryEmbeddingRes.data[0].embedding;

  // 2. Perform your vector database search using queryVector (omitted for brevity)
  const retrievedContext = [
    'Enterprise subscriptions include 24/7 dedicated telephone support.',
    'Basic plans receive support responses within 2 business days.',
  ].join('\n');

  // 3. Generate the response using a chat tier from a different lab
  const completion = await client.chat.completions.create({
    model: 'vibiz/smart',
    messages: [
      {
        role: 'system',
        content: `Answer the user question using only this context:\n${retrievedContext}`,
      },
      {
        role: 'user',
        content: userQuery,
      },
    ],
  });

  return completion.choices[0].message.content;
}

const answer = await answerQuestion('Do enterprise users get phone support?');
console.log(answer);
```

## Monitoring vector costs and managing limits

Vector ingestion can process hundreds of thousands of tokens at once. To prevent accidental overages, thelastapi enforces strict spend controls and transparent accounting:

- **Prepaid balance:** Accounts draw from a prepaid credit balance. New accounts start with $2 of trial credit, and you can add credits or set up auto-recharge in Billing.
- **Daily safety caps:** Each account has a daily spend ceiling on AI and actions ($5 per UTC day by default, adjustable up to $1,000 by account owners).
- **Project AI budgets:** Each project defaults to a $1 daily AI budget. An owner can change this in the console or by running `vibiz ai budget <dollars>`.
- **Request limits:** Project keys have a default rate limit of 120 requests and 200,000 tokens per minute (up to 25 in flight), which owners can raise to 600 requests and 2,000,000 tokens per minute. Account keys support 300 requests and 400,000 tokens per minute.

If your script hits a limit, the API answers with status `429` and a structured error describing the exact restriction:

```json
{
  "error": {
    "code": "rate_limited",
    "message": "Project daily AI budget reached.",
    "type": "invalid_request_error",
    "details": {
      "reason": "project_budget"
    }
  }
}
```

You can inspect the exact token count and cost of your embedding requests using the CLI:

```bash
vibiz usage --by model
vibiz usage --period 24h --by tool
```

You can review all account constraints on the [Usage and limits](https://thelastapi.dev/docs/usage) page, manage balances in [Billing and credits](https://thelastapi.dev/docs/billing), and explore model capabilities in our [AI documentation](https://thelastapi.dev/docs/ai).

To start indexing your data, initialize your project with `vibiz init` and begin generating vector embeddings with your project key.

## Frequently asked questions

### Can I change an existing RAG index from 1536 dimensions to 3072 dimensions?

No. Vectors of different dimensions cannot be compared in similarity calculations. If you switch from `vibiz/embed` to `vibiz/embed-large`, you must re-generate embeddings for all documents in your database index.

### How many inputs can I pass in a single embedding call?

You can send up to 2,048 inputs in an array per request to `POST /v1/ai/embeddings`.

### What happens if an embedding job exceeds my daily project budget?

The gateway refuses the request with an HTTP 429 status code and `details.reason: "project_budget"`. It does not execute partial jobs or bill your balance beyond the configured limit.

### Can I use my own Google key to generate embeddings?

Yes, but embeddings on your own Google key are disabled by default so you do not accidentally generate vectors that conflict with an existing index. You can enable them for a new index using `PATCH /v1/ai-keys/google` with `{"use_for": ["llm", "embeddings"]}`.

---

Published 2026-11-15 · https://thelastapi.dev/blog/embeddings-api-for-rag
