Skip to main content
This is the reference for integrating the OpenAI and Anthropic SDKs with SERV. For a five-minute setup, start with the Quickstart. SERV exposes three HTTP endpoints under one base URL: https://inference-api.openserv.ai
EndpointShapeUse it for
POST /v1/chat/completionsOpenAIUniversal. Works with every model in the catalog.
POST /v1/responsesOpenAIOpenAI models, with streamed reasoning summaries.
POST /v1/messagesAnthropicClaude and most other providers. See endpoint compatibility.

OpenAI SDK

Chat completions

import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference-api.openserv.ai/v1",
  apiKey: process.env.SERV_API_KEY,
});

const completion = await client.chat.completions.create({
  model: "gpt-5.4-mini",
  messages: [
    { role: "system", content: "You are a concise assistant." },
    { role: "user", content: "What is a CPU register?" },
  ],
});

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

Responses

Use the Responses API to receive the reasoning trace alongside the answer. OpenAI models only.
import OpenAI from "openai";

const client = new OpenAI({
  baseURL: "https://inference-api.openserv.ai/v1",
  apiKey: process.env.SERV_API_KEY,
});

const response = await client.responses.create({
  model: "gpt-5.4",
  instructions: "You are a careful reasoner.",
  input: "What is the integral of x^2 from 0 to 3?",
});

console.log(response.output_text);

Anthropic SDK

Messages

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic({
  baseURL: "https://inference-api.openserv.ai",
  authToken: process.env.SERV_API_KEY,
});

const message = await client.messages.create({
  model: "claude-haiku-4.5",
  max_tokens: 1024,
  system: "You answer in one sentence.",
  messages: [{ role: "user", content: "What is a CPU register?" }],
});

console.log(message.content.find(b => b.type === "text").text);

Important details

Base URL differs by SDK

SDKBase URLWhy
OpenAI SDKhttps://inference-api.openserv.ai/v1The OpenAI SDK expects /v1 in the base URL.
Anthropic SDKhttps://inference-api.openserv.aiThe Anthropic SDK appends /v1/messages itself. Including /v1 yourself would call /v1/v1/messages, which fails.

Auth field differs by SDK

SDKFieldNotes
OpenAI SDKapiKeyStandard.
Anthropic SDKauthTokenapiKey also works, but authToken keeps ANTHROPIC_API_KEY free if you ever fall back to direct Anthropic.

A system prompt is required

Every request needs a system, developer, or instructions message. Requests without one are rejected:
A system prompt is required. Please include a system or developer message in your request.
Where the system prompt goes depends on the endpoint:
EndpointWhere the system prompt goes
/v1/chat/completionsa { role: "system", content: "..." } message
/v1/responsestop-level instructions
/v1/messagestop-level system

Parameter map

Moving an integration across SDKs comes down to this mapping.
ConceptOpenAI ChatOpenAI ResponsesAnthropic Messages
HTTP path/v1/chat/completions/v1/responses/v1/messages
Auth field (SDK constructor)apiKeyapiKeyauthToken
baseURL suffix to use with SERV/v1/v1(none)
Token cap fieldmax_completion_tokensmax_output_tokensmax_tokens (required)
System promptmessage with role:"system"top-level instructionstop-level system
User message shape{role, content} in messages[]top-level input (string or array){role, content} in messages[]
Reasoning-effort controlreasoning_effortreasoning: { effort, summary }thinking: { type:"enabled", budget_tokens }
Streamingstream: truestream: truestream: true
Stop sequencesstopn/astop_sequences
Tool schematools: [{type:"function", function:{name, parameters}}]tools: [{type:"function", ...}]tools: [{name, input_schema}] (no nested function:)
Tool choicetool_choice: "auto" | {type:"function", function:{name}}tool_choice: ...tool_choice: "auto" | "any" | {type:"tool", name}
Response textchoices[0].message.contentoutput_text or output[] blockscontent[] array, find the type === "text" block
Token usageusage.prompt_tokens / completion_tokens / total_tokensusage.input_tokens / output_tokens / total_tokensusage.input_tokens / output_tokens
Cache metricsusage.prompt_tokens_details.cached_tokensusage.input_tokens_details.cached_tokensusage.cache_read_input_tokens, usage.cache_creation_input_tokens

See also