OpenAI SDK Integration

Use the official OpenAI SDK with LangMart by simply changing the base URL.

Python

Installation

pip install openai

Usage

from openai import OpenAI

client = OpenAI(
    base_url="https://api.langmart.ai/v1",
    api_key="your-langmart-api-key",
)

completion = client.chat.completions.create(
    model="openai/gpt-5.2",
    messages=[
        {"role": "user", "content": "Hello, how are you?"}
    ],
)

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

TypeScript / JavaScript

Installation

npm install openai

Usage

import OpenAI from "openai";

const openai = new OpenAI({
  baseURL: "https://api.langmart.ai/v1",
  apiKey: "your-langmart-api-key",
});

async function main() {
  const completion = await openai.chat.completions.create({
    model: "openai/gpt-5.2",
    messages: [
      { role: "user", content: "Hello, how are you?" }
    ],
  });

  console.log(completion.choices[0].message);
}

main();

Streaming

Python Streaming

stream = client.chat.completions.create(
    model="anthropic/claude-opus-4.5",
    messages=[{"role": "user", "content": "Write a short poem"}],
    stream=True,
)

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

TypeScript Streaming

const stream = await openai.chat.completions.create({
  model: "anthropic/claude-opus-4.5",
  messages: [{ role: "user", content: "Write a short poem" }],
  stream: true,
});

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

Configuration Options

Parameter Description
base_url / baseURL https://api.langmart.ai/v1
api_key / apiKey Your LangMart API key

Learn More