Skip to content

Completions (legacy)

Older code that sends a prompt to /v1/completions works through the gateway unchanged, so it's checked, charged and recorded like everything else while you plan its move to Chat Completions.

What it is

POST /v1/completions, OpenAI's original text-completion endpoint: a prompt in, text out. OpenAI itself marks it as legacy. The gateway passes it on unchanged to OpenAI and Azure OpenAI, and to a provider added with the OpenAI kind of API that still offers it. It isn't translated: a call to a Claude or Gemini model gets a 400.

The two settings

The same as for the OpenAI SDK: base address https://<your-gateway>/v1 and your Vidai key. See OpenAI SDK for Python.

A minimal call

from openai import OpenAI

client = OpenAI()  # reads OPENAI_BASE_URL and OPENAI_API_KEY

completion = client.completions.create(
    model="gpt-3.5-turbo-instruct",
    prompt="Say hello in Dutch:",
    max_tokens=20,
)
print(completion.choices[0].text)
import OpenAI from "openai";

const client = new OpenAI();

const completion = await client.completions.create({
  model: "gpt-3.5-turbo-instruct",
  prompt: "Say hello in Dutch:",
  max_tokens: 20,
});
console.log(completion.choices[0].text);
curl https://<your-gateway>/v1/completions \
  -H "Authorization: Bearer $OPENAI_API_KEY" -H "Content-Type: application/json" \
  -d '{"model": "gpt-3.5-turbo-instruct", "prompt": "Say hello in Dutch:", "max_tokens": 20}'

The model name is an example: use one your organisation approved under Models that the provider serves on this endpoint.

Streaming

stream=True works as OpenAI documents it; the chunks are the provider's own, passed through. As with chat, a fallback model is tried only before the first byte.

Reading what the gateway did

Use client.completions.with_raw_response.create(...) (Python) or .withResponse() (TypeScript) and read x-vidai-request-id and x-vidai-model, as shown on Chat Completions.

Errors

The codes are those of Chat Completions. Specific to this endpoint: a model on a provider that doesn't speak the OpenAI API (Claude, Gemini, Bedrock) gets a 400, and nothing is sent.

What goes through the gateway

Feature Through the gateway
completions.create, streaming Yes, to OpenAI and Azure OpenAI
Claude, Gemini and Bedrock models No: a 400. Use Chat Completions

Check it works in a minute

Run the curl above. A short answer means the address, key and model are right; the call shows in Request logs within seconds.

Good to know

  • On this endpoint, a guardrail set to mask blocks the call instead.
  • Moving to Chat Completions opens every provider to the same code: a prompt becomes messages=[{"role": "user", "content": prompt}].