Using an OpenAI SDK with Revoye
- Updated
- Reading time
- 2 min
- Level
- beginner
Change base_url to https://api.revoye.com/v1, use your Revoye key as the API key, and set the model to
revoye/auto. The SDK call waits for the response and returns it in choices[0].message.content,
exactly as it would from OpenAI. Everything else about your request code stays as it is.
Python
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.revoye.com/v1",
api_key=os.environ["REVOYE_KEY"],
timeout=660, # seconds; a request can be held for up to 10 minutes
)
completion = client.chat.completions.create(
model="revoye/auto",
messages=[{"role": "user", "content": "Rewrite this paragraph in a friendlier tone: …"}],
)
print(completion.choices[0].message.content)TypeScript
import OpenAI from "openai";
const client = new OpenAI({
baseURL: `${process.env.REVOYE_API_BASE}/v1`,
apiKey: process.env.REVOYE_KEY,
timeout: 660_000, // milliseconds; a request can be held for up to 10 minutes
});
const completion = await client.chat.completions.create({
model: "revoye/auto",
messages: [{ role: "user", content: "Summarise this support ticket in two sentences: …" }],
});
console.log(completion.choices[0].message.content);Most responses arrive in 3 to 90 seconds. Set the client timeout above the 10-minute hold so the SDK never gives up before Revoye answers.
What differs
A slow request comes back as an error with its id. If a request is still being processed after
10 minutes, the call returns 504 JOB_TIMEOUT, which the SDK raises as an API error. The request
keeps running: its id is in details.job_id, and the response can be collected from
GET /v1/completions/{id}. A request that fails or is cancelled is raised
the same way, with the same envelope as the native endpoint.
You can accept now and collect later. Pass revoye_wait: false through extra_body and the call
returns 202 straight away, with the job id in id and choices[0].message.content set to null.
Collect the response by id, or use the native endpoint with a callback_url to
take a webhook.
Messages are flattened. system messages come first and the other turns follow as context, all
in a single request. To follow up on an earlier response, use the native endpoint with
conversation_ref and mode: "continue".
stream: true returns 400. Revoye returns complete responses. Any UI code that assumes a
stream needs a non-streaming path before it can talk to Revoye.
usage is null. Guard any code that does arithmetic on it — cost estimation, budget
enforcement, context-window maths — because None + int is the failure you will hit first. Your
token use is in the dashboard and in quota on GET /v1/status.
Desk or Cloud
To pin a request to one channel, set a default header on the client —
default_headers={"Revoye-Channel": "cloud"} in Python, defaultHeaders: { 'Revoye-Channel': 'cloud' }
in TypeScript — or pass revoye_channel through extra_body per request. Leave both out and your
plan and routing preference decide. A channel your plan does not include is refused with
CHANNEL_NOT_ENTITLED, never re-routed.
Model pickers
GET /v1/models returns the models your plan can use in OpenAI's list shape, with revoye/auto
first. A picker built against an OpenAI client populates itself with no changes.
What you give up
The compatibility layer covers the everyday call. The rest of what Revoye offers lives on
/v1/completions: webhooks, per-attempt timeouts, deadlines, priority,
metadata, and continuing a conversation. Use the OpenAI SDK to reuse code you already have, and the
native endpoint when you need those.