Backend client examples
Send one endpoint or Application request from Python or JavaScript and capture the Smol request ID without an automatic replay.
Choose one example. Each makes a real request. Both use standard HTTPS from a backend; neither requires a Smol package. Do not paste these into a browser. For a production service, obtain and cache a short-lived access token with client credentials and store the request intent before dispatch.
Set SMOL_INFERENCE_URL, SMOL_MODEL_ID, SMOL_ACCESS_TOKEN and SMOL_REQUEST_KEY as described in Send a chat completion. The URL must come from your trusted endpoint configuration, not user input. A request ID in the response identifies the Smol activity record; keep it even if the answer is unusable.
Python 3
Section titled “Python 3”import http.clientimport jsonimport osfrom urllib.parse import urlsplit
url = urlsplit(os.environ["SMOL_INFERENCE_URL"])if url.scheme != "https" or not url.hostname or url.username or url.password or url.query or url.fragment: raise ValueError("Use the HTTPS inference URL from Connect")request_key = os.environ["SMOL_REQUEST_KEY"]if not request_key: raise ValueError("Retain a request key before dispatch")body = { "model": os.environ["SMOL_MODEL_ID"], "messages": [{"role": "user", "content": "Name one benefit of a shared glossary."}], "max_tokens": 128, "stream": False,}connection = http.client.HTTPSConnection(url.netloc, timeout=90)try: connection.request("POST", url.path, body=json.dumps(body).encode(), headers={ "Authorization": "Bearer " + os.environ["SMOL_ACCESS_TOKEN"], "Content-Type": "application/json", "Idempotency-Key": request_key, }) response = connection.getresponse() request_id = response.getheader("X-Smol-Request-Id") if request_id: print("Request ID:", request_id) if response.status != 200: raise RuntimeError(f"HTTP {response.status}; inspect request status before another submission") answer = json.loads(response.read()) print(answer["choices"][0]["message"]["content"])finally: connection.close()JavaScript · Node.js
Section titled “JavaScript · Node.js”Run as a server-side ES module (.mjs) on Node.js 22 or later.
const url = new URL(process.env.SMOL_INFERENCE_URL);if (url.protocol !== "https:" || url.username || url.password || url.search || url.hash) { throw new Error("Use the HTTPS inference URL from Connect");}const { SMOL_ACCESS_TOKEN, SMOL_MODEL_ID, SMOL_REQUEST_KEY } = process.env;if (!SMOL_ACCESS_TOKEN || !SMOL_MODEL_ID || !SMOL_REQUEST_KEY) { throw new Error("Set the access token, model and retained request key before dispatch");}const response = await fetch(url, { method: "POST", redirect: "error", signal: AbortSignal.timeout(90_000), headers: { Authorization: "Bearer " + SMOL_ACCESS_TOKEN, "Content-Type": "application/json", "Idempotency-Key": SMOL_REQUEST_KEY, }, body: JSON.stringify({ model: SMOL_MODEL_ID, messages: [{ role: "user", content: "Name one benefit of a shared glossary." }], max_tokens: 128, stream: false, }),});const requestId = response.headers.get("X-Smol-Request-Id");if (requestId) console.log("Request ID:", requestId);if (response.status !== 200) { throw new Error("HTTP " + response.status + "; inspect request status before another submission");}const answer = await response.json();console.log(answer.choices[0].message.content);Both examples make one attempt. A timeout, cancellation or malformed success response can occur after work was accepted. Record it against the same intent and use readback; do not put either example in a general-purpose HTTP retry loop.