Skip to content

Embeddings with OpenAI SDKs

Create text embeddings with the stock OpenAI SDKs, from Python, TypeScript or curl.

Updated View as Markdown

EZGH Inference’s embeddings endpoint is OpenAI’s. Point an OpenAI SDK at your project’s base URL and give it an EZGH API key; nothing else changes.

Before you start

  • Base URL: your project’s, with its organization and project IDs (in the console, the Quickstart on a model’s page shows it filled in):

    https://inference-api.ezghcloud.com/v1/organizations/<org-id>/projects/<project-id>/openai/v1
  • API key: an API key whose owner has inference.models.invoke on the project (InferenceFullAccess), in EZGH_API_KEY. OAuth access tokens and OIDC API keys work too. The API takes bearer credentials only, never cookies.

Create embeddings

pip install openai
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://inference-api.ezghcloud.com/v1/organizations/<org-id>/projects/<project-id>/openai/v1",
    api_key=os.environ["EZGH_API_KEY"],
)
r = client.embeddings.create(model="qwen3-embedding-0.6b", input=["Instruct: Given a web search query, retrieve relevant passages\nQuery: what is a vector database"])
print(len(r.data[0].embedding))
npm install openai
import OpenAI from "openai"

const client = new OpenAI({
  baseURL: "https://inference-api.ezghcloud.com/v1/organizations/<org-id>/projects/<project-id>/openai/v1",
  apiKey: process.env.EZGH_API_KEY,
})
const r = await client.embeddings.create({
  model: "qwen3-embedding-0.6b",
  input: ["Instruct: Given a web search query, retrieve relevant passages\nQuery: what is a vector database"],
})
console.log(r.data[0].embedding.length)
curl https://inference-api.ezghcloud.com/v1/organizations/<org-id>/projects/<project-id>/openai/v1/embeddings \
  -H "Authorization: Bearer $EZGH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "qwen3-embedding-0.6b", "input": ["Instruct: Given a web search query, retrieve relevant passages\nQuery: what is a vector database"]}'

The response is OpenAI’s, with the model version that ran:

{
  "object": "list",
  "data": [{ "object": "embedding", "index": 0, "embedding": [0.0123, -0.0456] }],
  "model": "qwen3-embedding-0.6b:1.0.0",
  "usage": { "prompt_tokens": 7, "total_tokens": 7 }
}

See create embeddings in the API reference.

Queries and documents

qwen3-embedding-0.6b is instruction-aware. For retrieval, write each query with a one-line task description, and send documents as they are:

Instruct: Given a web search query, retrieve relevant passages
Query: what is a vector database

The instruction is part of your input; there’s no separate parameter. Use the same instruction for every query in an index, in English even when the text isn’t.

Request fields

Field Values
model qwen3-embedding-0.6b, or a pinned version, qwen3-embedding-0.6b:1.0.0. See Models.
input A string, or an array of 1 to 128 strings. Empty strings are refused. Each input is at most 8,192 tokens. Arrays of token IDs are refused with token_input_unsupported.
dimensions Optional: 32 to 1,024 (the default). Shorter vectors are truncated and normalized (Matryoshka).
encoding_format float (the default) or base64: little-endian 32-bit floats, base64-encoded.
user Accepted and ignored.

Other fields are ignored. A request body is at most 1 MiB.

The responses carry x-ratelimit-* headers; see Limits and errors, with every error code. The OpenAI SDKs retry 429 and 5xx answers, honoring Retry-After, except the monthly token limit (insufficient_quota).

LangChain

LangChain’s OpenAIEmbeddings needs two settings:

  • check_embedding_ctx_length=False: by default it splits text with OpenAI’s tokenizer and sends token IDs, which the API refuses (token_input_unsupported).
  • chunk_size=128: it sends up to 1,000 inputs per request by default, and a request takes at most 128, so embedding more than 128 documents at once would fail with invalid_request.
import os
from langchain_openai import OpenAIEmbeddings

embeddings = OpenAIEmbeddings(
    model="qwen3-embedding-0.6b",
    base_url="https://inference-api.ezghcloud.com/v1/organizations/<org-id>/projects/<project-id>/openai/v1",
    api_key=os.environ["EZGH_API_KEY"],
    check_embedding_ctx_length=False,
    chunk_size=128,
)

Data

Inputs and embeddings are never stored, logged or recorded. A refused request appears in Trails, with its error code; a successful one doesn’t.

Navigation

Type to search…

↑↓ navigate↵ selectEsc close