Skip to content

Client integration

Because dlm serve speaks both the OpenAI API and the Anthropic Messages API, clients for either work unchanged — point the base URL at dlm. The model name can be anything — dlm serves one model.

Connection details

Python (openai SDK)

$pip install openai
$ python
  from openai import OpenAI
  client = OpenAI(
      base_url="http://127.0.0.1:8000/v1",
      api_key="dlm",
  )
  resp = client.chat.completions.create(
      model="dlm",
      messages=[{"role": "user", "content": "Hello"}],
  )
  print(resp.choices[0].message.content)
Pass stream=True to iterate tokens as they arrive — dlm sends them as Server-Sent Events. client.embeddings.create(...) works too: the SDK asks for base64-encoded vectors by default, which dlm serves.

Node (openai SDK)

$ node
  import OpenAI from "openai";
  const client = new OpenAI({
    baseURL: "http://127.0.0.1:8000/v1",
    apiKey: "dlm",
  });
  const r = await client.chat.completions.create({
    model: "dlm",
    messages: [{ role: "user", content: "Hello" }],
  });

curl

$curl http://127.0.0.1:8000/v1/chat/completions -H 'Content-Type: application/json' -d '{"model":"dlm","messages":[{"role":"user","content":"Hello"}]}'

Open WebUI

In Settings → Connections, add an OpenAI API connection with the base URL http://127.0.0.1:8000/v1 and any API key. The served model appears in the model picker under its checkpoint name.

Browser apps

A web page calling dlm directly from the browser needs the server to allow its origin — start it with --cors-origin. Without it the request succeeds but the browser discards the reply. Clients that call from a server (Open WebUI, the SDKs) don’t need it.

$dlm serve --model-path /path/to/model --cors-origin http://localhost:3000

LangChain

$ python
  from langchain_openai import ChatOpenAI
  llm = ChatOpenAI(
      base_url="http://127.0.0.1:8000/v1",
      api_key="dlm",
      model="dlm",
  )
  print(llm.invoke("Hello").content)

See the HTTP API reference for the full set of endpoints, sampling parameters, and usage fields.

Anthropic SDK

dlm also serves the Anthropic Messages API at /v1/messages, so the anthropic SDK works too — set its base URL to the dlm server and use x-api-key for auth. Both non-streaming and streaming (client.messages.stream) responses are supported.

$pip install anthropic
$ python
  from anthropic import Anthropic
  client = Anthropic(
      base_url="http://127.0.0.1:8000",
      api_key="dlm",
  )
  msg = client.messages.create(
      model="dlm",
      max_tokens=128,
      messages=[{"role": "user", "content": "Hello"}],
  )
  print(msg.content[0].text)

Stream tokens as they arrive:

$ python
  with client.messages.stream(
      model="dlm",
      max_tokens=128,
      messages=[{"role": "user", "content": "Hello"}],
  ) as stream:
      for text in stream.text_stream:
          print(text, end="")
The Anthropic SDK appends /v1/messages to the base URL, so set base_url to the server root (no /v1). See the HTTP API reference for the request and response shapes.