SDK
Keep your existing OpenAI client workflow.
Use the OpenAI SDK with the LineMod base URL and API key, or copy a language-specific example from Console. Chat completions do not require a LineMod-specific SDK.
Recommended
OpenAI-compatible clients
Set
base_url (Python) or baseURL (Node.js) to https://api.linemod.ai/v1 and use a LineMod API key. Keep the same chat completions request format.Pythonopenai package
pip install openai
from openai import OpenAI
import os
client = OpenAI(
base_url="https://api.linemod.ai/v1",
api_key=os.environ["LINEMOD_API_KEY"],
)
client.chat.completions.create(
model="auto:balanced",
messages=[{"role": "user", "content": "Hello"}],
)Node.jsopenai package
npm install openai
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.linemod.ai/v1",
apiKey: process.env.LINEMOD_API_KEY,
});
await client.chat.completions.create({
model: "auto:balanced",
messages: [{ role: "user", content: "Hello" }],
});cURLstreaming
curl https://api.linemod.ai/v1/chat/completions \
-H "Authorization: Bearer $LINEMOD_API_KEY" \
-H "Content-Type: application/json" \
-d '{"model":"auto:balanced","stream":true,
"messages":[{"role":"user","content":"Hello"}]}'Goany HTTP client
req.Header.Set("Authorization", "Bearer "+apiKey)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-LineMod-Tag", "worker-pool")Scenarios
Set LineMod request headers in SDK calls
Use
extra_headers to set LineMod headers for an individual request.Pythonextra_headers
client.chat.completions.create(
model="auto:cost",
messages=[{"role": "user", "content": "Classify tickets"}],
extra_headers={
"X-LineMod-Session-Id": "session_123",
"X-LineMod-Cost-Quality": "3",
"X-LineMod-Tag": "batch-classify",
},
)Endpointhttps://api.linemod.ai/v1
AuthBearer LINEMOD_API_KEY
Streamingstream=True / stream: true
Snippets/console/sdk-snippets
Agent observability
Link requests to an agent run
Reuse the same
X-LineMod-Run-Id for every request in an agent run. Optionally send X-LineMod-Client to compare spending and review run diagnostics in Console. See v1.1.0 release notes.Pythonagent loop
import os
import uuid
from openai import OpenAI
client = OpenAI(
base_url="https://api.linemod.ai/v1",
api_key=os.environ["LINEMOD_API_KEY"],
)
run_id = str(uuid.uuid4())
def agent_step(messages):
return client.chat.completions.create(
model="auto:balanced",
messages=messages,
extra_headers={
"X-LineMod-Run-Id": run_id,
"X-LineMod-Client": "cursor",
"X-LineMod-Tag": "coding-agent",
},
)After each request
- Log
X-LineMod-Request-Id,X-LineMod-Client-Profile, andX-LineMod-Run-Costfrom response headers. - Review the run in Audit or compare agents in Agent insights.
- Copy header examples from SDK snippets in Console.
Migration
Move from a direct provider connection
Migration checklist
- Replace the provider base URL with
https://api.linemod.ai/v1. - Store a LineMod API key (
sr_gl_...) in your deployment secret store. - To use LineMod routing, replace hard-coded model IDs with
auto:balancedor anotherauto:*alias. - Log
X-LineMod-Request-IdandX-LineMod-Model-Usedwith your app request ID. - Configure security templates and routing rules in Console before production traffic.
- Optional: connect BYOK provider keys for hybrid billing — see pricing.