HTTP wrappers
Automatically track outbound HTTP calls (OpenAI, Stripe, internal APIs) without manual track() at every call site.
Node.js — wrapFetch
typescript
import { AmlexiaClient, wrapFetch } from '@amlexiahq/node';
const client = AmlexiaClient.fromEnv();
const baseFetch = globalThis.fetch;
globalThis.fetch = wrapFetch(client, baseFetch);
// All fetch() calls are now tracked with URL, method, status, latency
const res = await fetch('https://api.openai.com/v1/chat/completions', { ... });Single call — trackHttpCall
typescript
import { trackHttpCall } from '@amlexiahq/node';
await trackHttpCall(client, {
url: 'https://api.stripe.com/v1/charges',
method: 'POST',
statusCode: 200,
latencyMs: 180,
});Provider is inferred from hostname when possible.
Python — Requests
python
import requests
from amlexia import AmlexiaClient
from amlexia.http_wrap import wrap_requests_session
client = AmlexiaClient.from_env()
session = wrap_requests_session(client, requests.Session())
r = session.get("https://api.openai.com/v1/models")Python — urllib
python
from amlexia.http_wrap import wrap_urllib_opener, track_http_callGo
Use the HTTP transport wrapper in amlexia-go (wraps http.RoundTripper).
Ruby
Use the gem’s HTTP helper modules (see sdks/ruby README).
What gets recorded
| Field | Source |
|---|---|
endpoint | Path or normalized URL |
method | HTTP method |
statusCode | Response status |
latencyMs | Wall time |
provider | Hostname detection (override if wrong) |
Add tokens/cost manually for LLM responses, or use LLM helpers after the call.
