Menu: LangChain

Guides

LangChain

Point LangChain's OpenAI chat model at Scalaix, in Python and JavaScript.

Python

pip install langchain-openai
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="gpt-4o-mini",
    base_url="https://www.scalaix.com/v1",
    api_key=os.environ["SCALAIX_API_KEY"],
    temperature=0,
)

print(llm.invoke("Give me one sentence about vector databases.").content)

Structured output works through the OpenAI JSON schema support:

from pydantic import BaseModel

class Ticket(BaseModel):
    category: str
    priority: int

classifier = llm.with_structured_output(Ticket)
print(classifier.invoke("Customer was charged twice and is angry."))

JavaScript

npm install @langchain/openai
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "claude-3-5-haiku-latest",
  apiKey: process.env.SCALAIX_API_KEY,
  configuration: { baseURL: "https://www.scalaix.com/v1" },
});

const msg = await llm.invoke("Summarize the CAP theorem in one line.");
console.log(msg.content);

Any model id from Models works, including Anthropic and Google models: Scalaix answers in the OpenAI format either way.

Calling a published endpoint from a chain

A published endpoint is a plain HTTP call, so wrap it as a tool or a runnable:

import requests
from langchain_core.tools import tool

@tool
def classify_ticket(subject: str, body: str) -> dict:
    """Classify a support ticket into category and priority."""
    r = requests.post(
        "https://www.scalaix.com/acme/support/classify-ticket",
        headers={"Authorization": f"Bearer {os.environ['SCALAIX_API_KEY']}"},
        json={"inputs": {"ticket": {"subject": subject, "body": body}}},
        timeout=60,
    )
    r.raise_for_status()
    return r.json()["data"]