SDK examples
Call DurinDoor with the OpenAI SDK, the Anthropic SDK, or curl.
Start DurinDoor, connect a provider, and create a client key. Choose an ID from GET /v1/models. Replace PROVIDER/MODEL below with that ID. Production listens on port 20128.
Install the SDK you use:
npm install openai @anthropic-ai/sdkpython -m pip install openai anthropicRun JavaScript examples as ES modules, or Python examples as Python scripts.
POST /v1/chat/completions and POST /v1/messages both reject a non-JSON Content-Type with HTTP 415 before reading the body. Send application/json.
When Require API Key is on, send the DurinDoor secret. OpenAI-shaped clients use Authorization: Bearer. Anthropic-shaped clients usually send x-api-key; DurinDoor accepts that header too.
OpenAI SDK
The OpenAI client appends /chat/completions to base_url / baseURL. That value must already end in /v1, so the request lands on /v1/chat/completions.
import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_DURINDOOR_API_KEY",
baseURL: "http://localhost:20128/v1",
});
const response = await client.chat.completions.create({
model: "PROVIDER/MODEL",
messages: [{ role: "user", content: "Say hello." }],
});
console.log(response.choices[0].message.content);Set stream: true on the same create call (or "stream": true in the JSON body) to receive SSE. Iterate over the returned stream to read chunks. A successful non-streaming OpenAI call prints the assistant text.
Anthropic SDK
POST /v1/messages is always treated as Claude format. The official Anthropic client appends /v1/messages to its base URL. Pass the origin only: http://localhost:20128. Passing /v1 here would request /v1/v1/messages.
OpenAI baseURL includes /v1. Anthropic baseURL / base_url does not.
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
apiKey: "YOUR_DURINDOOR_API_KEY",
baseURL: "http://localhost:20128",
});
const message = await client.messages.create({
model: "PROVIDER/MODEL",
max_tokens: 32,
messages: [{ role: "user", content: "Say hello." }],
});
console.log(message.content);Claude-format bodies need max_tokens. A successful call prints the message content blocks. Streaming (stream: true) sends Anthropic SSE with ping frames while waiting for the provider.
If the client requests /v1/v1/messages, remove /v1 from the Anthropic base URL. For 401, check the DurinDoor key. For a model error, use an ID from your instance. Translation does not guarantee support for every upstream option; test streaming, tools, and images before using them in an application.