OpenAI SDK Compatibility — ML Junction docs
Point the official OpenAI SDK at /openai/v1. Chat Completions supports sync/async text, SSE streaming, tools and streamed arguments, strict structured output, reasoning effort, usage, request IDs, and ML Junction extensions.
import OpenAI from 'openai';
const client = new OpenAI({
apiKey: process.env.ASTRO_API_KEY,
baseURL: 'https://api.mljunction.com/openai/v1',
});
const completion = await client.chat.completions.create({
model: 'gpt-5.5',
messages: [
{ role: 'system', content: 'Be precise and concise.' },
{ role: 'user', content: 'Explain token caching.' },
],
temperature: 0.3,
max_completion_tokens: 1200,
});
console.log(completion.choices[0].message.content); console.log(completion.usage);
from openai import OpenAI
client = OpenAI(
api_key=os.environ["ASTRO_API_KEY"],
base_url="https://api.mljunction.com/openai/v1",
)
completion = client.chat.completions.create(
model="gpt-5.5",
messages=[
{"role": "system", "content": "Be precise and concise."},
{"role": "user", "content": "Explain token caching."},
],
temperature=0.3,
max_completion_tokens=1200,
)
print(completion.choices[0].message.content) print(completion.usage)
Pass ML Junction-only controls through extra_body={"mlj": {...}} in Python or the mlj request property in JavaScript. The response includes mlj.routing, mlj.receipt, mlj.warnings, mlj.reasoning, and mlj.observability without changing standard SDK fields.
Canonical URL: https://mljunction.com/docs/openai-compatibility