SDK
Keep your existing OpenAI client workflow.
LineMod is a security gateway with agent behavior observability—guardrails at the edge, harness diagnostics across runs, and policy routing when you need it. This page shows how to point an existing OpenAI client at LineMod. Point the official OpenAI SDK at LineMod, or copy language-specific snippets from the Console — no proprietary client required for chat completions.
Recommended
OpenAI-compatible clients
Change only
base_url / baseURL and the API key. The request body stays identical.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" }],
});Scenarios
Routing and security headers in SDK calls
Pass LineMod headers through your HTTP client when you need per-request policy tuning.
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
Other runtimes
Go, cURL, and community SDKs
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")Agent observability
Link runs and declare client type
Multi-step agents should reuse one
X-LineMod-Run-Id per run and optionally send X-LineMod-Client so Console can compare spend and surface harness diagnostics. 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 response
- 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
Checklist from a direct provider
Before you cut over
- Replace the provider base URL with
https://api.linemod.ai/v1. - Store a LineMod API key (
sr_gl_...) in your deployment secret store. - Swap hard-coded model names for
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.