Guides
Use the OpenAI SDK
Point an existing OpenAI client at Deeplinq and stream a response.
Deeplinq implements the OpenAI chat-completions and models surfaces. Configure the SDK with the engine base URL and a Deeplinq credential.
TypeScript
import OpenAI from "openai"
const client = new OpenAI({
apiKey: process.env.DEEPLINQ_API_KEY,
baseURL: `${process.env.DEEPLINQ_BASE_URL}/v1`,
})
const stream = await client.chat.completions.create({
model: "auto",
stream: true,
messages: [{ role: "user", content: "Explain reciprocal rank fusion." }],
})
for await (const event of stream) {
process.stdout.write(event.choices[0]?.delta.content ?? "")
}Python
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["DEEPLINQ_API_KEY"],
base_url=f'{os.environ["DEEPLINQ_BASE_URL"]}/v1',
)
response = client.chat.completions.create(
model="auto",
messages=[
{
"role": "user",
"content": "Explain reciprocal rank fusion.",
}
],
)
print(response.choices[0].message.content)Tenant attribution
When using an organization-scoped API key, set X-End-User-Id through the
SDK's default headers:
const client = new OpenAI({
apiKey: process.env.DEEPLINQ_API_KEY,
baseURL: `${process.env.DEEPLINQ_BASE_URL}/v1`,
defaultHeaders: {
"X-End-User-Id": authenticatedUser.id,
},
})Only derive this value from your authenticated server-side session. Do not forward an untrusted client header directly.