Jectora accepts OpenAI-compatible requests. Existing applications usually need only two configuration changes: use a Jectora API key and set the Jectora base URL.
Install the SDK
npm install openaipip install openaiSet JECTORA_API_KEY in the server environment before running either example.
Chat Completions
Replace your-model-id with a chat-capable model from the
model catalog.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: process.env.JECTORA_API_KEY,
baseURL: "https://api.jectora.com/v1",
});
const completion = await client.chat.completions.create({
model: "your-model-id",
messages: [
{ role: "user", content: "Say hello in one short sentence." },
],
});
console.log(completion.choices[0]?.message.content);import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["JECTORA_API_KEY"],
base_url="https://api.jectora.com/v1",
)
completion = client.chat.completions.create(
model="your-model-id",
messages=[
{"role": "user", "content": "Say hello in one short sentence."}
],
)
print(completion.choices[0].message.content)Streaming responses
Streaming reduces the time before a user sees the first output. Set
stream: true on a compatible request and process each event until the stream
ends.
const stream = await client.chat.completions.create({
model: "your-model-id",
messages: [{ role: "user", content: "Write a two-line welcome message." }],
stream: true,
});
for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content ?? "");
}stream = client.chat.completions.create(
model="your-model-id",
messages=[
{"role": "user", "content": "Write a two-line welcome message."}
],
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="", flush=True)cURL and server-sent events
curl --no-buffer "https://api.jectora.com/v1/chat/completions" \
--header "Authorization: Bearer ${JECTORA_API_KEY}" \
--header "Content-Type: application/json" \
--data '{
"model": "your-model-id",
"messages": [{ "role": "user", "content": "Say hello." }],
"stream": true
}'The HTTP response uses server-sent events. Each data: event contains a JSON
chunk; the stream finishes with data: [DONE] for Chat Completions.
Handle interruptions
- Set a request timeout that fits the workload and model.
- Stop reading when the downstream client disconnects.
- Preserve output only after your application validates each chunk.
- Record the response
X-Request-Idwhen diagnosing a failed request. - Do not blindly replay a stream after output has started; the original request may already have consumed tokens and produced user-visible output.
For retryable failures before output begins, use bounded exponential backoff with jitter. See Errors and retries.
Responses
For models that support the Responses API:
const response = await client.responses.create({
model: "your-model-id",
input: "Summarize the benefits of a unified model API.",
});
console.log(response.output_text);response = client.responses.create(
model="your-model-id",
input="Summarize the benefits of a unified model API.",
)
print(response.output_text)Embeddings
For an embedding-capable model:
const result = await client.embeddings.create({
model: "your-embedding-model-id",
input: "Hello from Jectora.",
});
console.log(result.data[0]?.embedding);result = client.embeddings.create(
model="your-embedding-model-id",
input="Hello from Jectora.",
)
print(result.data[0].embedding)