Skip to main content

OpenAI SDK Integration

The OpenAI SDK is the most straightforward way to integrate Vexrail. You configure the SDK to point at the Vexrail API and pass your authentication keys.

JavaScript / TypeScript

Installation

npm install openai

Setup

import OpenAI from "openai";

const client = new OpenAI({
baseURL: "https://api.vexrail.com/v1",
apiKey: "unused", // Required by SDK but not used for auth
defaultHeaders: {
"x-publishable-key": process.env.VEXRAIL_PUBLISHABLE_KEY,
"x-secret-key": process.env.VEXRAIL_SECRET_KEY,
"x-conversation-id": "your-conversation-id",
},
});

Chat Completion

const response = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "system", content: "You are a helpful assistant." },
{ role: "user", content: "What tools can help me with project management?" },
],
});

console.log(response.choices[0].message.content);

Streaming

const stream = await client.chat.completions.create({
model: "gpt-4o-mini",
messages: [
{ role: "user", content: "Recommend a good design tool." },
],
stream: true,
});

for await (const chunk of stream) {
process.stdout.write(chunk.choices[0]?.delta?.content || "");
}

Python

Installation

pip install openai

Setup

from openai import OpenAI

client = OpenAI(
base_url="https://api.vexrail.com/v1",
api_key="unused", # Required by SDK but not used for auth
default_headers={
"x-publishable-key": "pk_live_your_publishable_key",
"x-secret-key": "sk_live_your_secret_key",
"x-conversation-id": "your-conversation-id",
},
)

Chat Completion

response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What tools can help me with project management?"},
],
)

print(response.choices[0].message.content)

Streaming

stream = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "user", "content": "Recommend a good design tool."},
],
stream=True,
)

for chunk in stream:
if chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")

Environment Variables

We recommend storing your keys in environment variables:

VEXRAIL_PUBLISHABLE_KEY=pk_live_your_publishable_key
VEXRAIL_SECRET_KEY=sk_live_your_secret_key

Then reference them in your code instead of hardcoding the values.

Next Steps