Configuration

weflayr_setup(settings) must be called once, before any call to weflayr_instrument.

weflayr_setup({
  intake_url:    'https://api.weflayr.com',
  client_id:     'your-client-id',
  client_secret: 'your-client-secret',
  methods: [],
});
from weflayr import weflayr_setup

weflayr_setup({
    "intake_url":    "https://api.weflayr.com",
    "client_id":     "your-client-id",
    "client_secret": "your-client-secret",
    "methods": [],
})

Credentials are typically loaded from environment variables via dotenv:

weflayr_setup({
  intake_url:    process.env.WEFLAYR_INTAKE_URL,
  client_id:     process.env.WEFLAYR_CLIENT_ID,
  client_secret: process.env.WEFLAYR_CLIENT_SECRET,
  methods: [],
});
import os
from weflayr import weflayr_setup

weflayr_setup({
    "intake_url":    os.environ["WEFLAYR_INTAKE_URL"],
    "client_id":     os.environ["WEFLAYR_CLIENT_ID"],
    "client_secret": os.environ["WEFLAYR_CLIENT_SECRET"],
    "methods": [],
})

Settings reference

Field Type Required Description
intake_url string Base URL of the Weflayr intake API
client_id string UUID identifying your Flayr credential pair
client_secret string Bearer token used to authenticate events
event_mode 'default' | 'light'   light skips before events. Default: 'default'
enabled boolean   Set to false to disable instrumentation entirely. Default: true
default_tags object   Key-value tags attached to every instrumented call. Overridden by per-call __weflayr_tags.
ignore_fields function   Middleware to strip sensitive fields from event payloads. Mutually exclusive with allow_fields.
allow_fields function   Middleware to keep only approved fields in event payloads. Mutually exclusive with ignore_fields.
methods MethodConfig[]   Methods to instrument on the proxied object

enabled

Set enabled: false to disable instrumentation entirely. weflayr_setup becomes a no-op and weflayr_instrument returns the original object untouched.

weflayr_setup({
  intake_url:    '...',
  client_id:     '...',
  client_secret: '...',
  enabled: false,
  methods: [],
});
weflayr_setup({
    "intake_url":    "...",
    "client_id":     "...",
    "client_secret": "...",
    "enabled": False,
    "methods": [],
})

event_mode

Controls which events are emitted per call.

Value Before event After event Error event
default
light

Use light to reduce event volume when you only care about outcomes, not request payloads.


ignore_fields

A middleware function that receives a deep clone of the event payload and returns the filtered version. Use it to strip sensitive fields before events reach the intake API. The original args forwarded to the real provider call are never affected.

weflayr_setup({
  // ...
  ignore_fields: (data) => {
    (data.messages ?? []).forEach(m => delete m.content);
    (data.choices  ?? []).forEach(c => { if (c.message) delete c.message.content; });
    return data;
  },
  methods: [{ call: 'chat.completions.create' }],
});
def ignore_fn(data):
    for m in (data.get("messages") or []):
        m.pop("content", None)
    for c in (data.get("choices") or []):
        if c.get("message"):
            c["message"].pop("content", None)
    return data

weflayr_setup({
    # ...
    "ignore_fields": ignore_fn,
    "methods": [{"call": "chat.completions.create"}],
})

allow_fields

A middleware function that receives a deep clone of the event payload and returns only the fields you want to keep. Everything else is dropped.

weflayr_setup({
  // ...
  allow_fields: (data) => ({
    model: data.model,
    usage: data.usage,
  }),
  methods: [{ call: 'chat.completions.create' }],
});
weflayr_setup({
    # ...
    "allow_fields": lambda data: {"model": data.get("model"), "usage": data.get("usage")},
    "methods": [{"call": "chat.completions.create"}],
})

ignore_fields and allow_fields are mutually exclusive. Setting both logs a warning and blocks all events from being sent.


default_tags

Static key-value tags attached to every instrumented call. Useful for metadata that doesn’t change between calls — app name, version, environment.

weflayr_setup({
  // ...
  default_tags: {
    app: 'my-app',
    version: '1.2.0',
  },
  methods: [{ call: 'chat.completions.create' }],
});
weflayr_setup({
    # ...
    "default_tags": {
        "app": "my-app",
        "version": "1.2.0",
    },
    "methods": [{"call": "chat.completions.create"}],
})

Per-call __weflayr_tags override default_tags for matching keys. Tags set via weflayr_propagate also override default_tags.


weflayr_propagate

weflayr_propagate(key, value) adds or overrides a single key in the runtime default tags without modifying the original weflayr_setup configuration. Call it anywhere in your code — inside a request handler, middleware, or function — to propagate context (e.g. a customer ID) to all subsequent instrumented calls.

const { weflayr_propagate } = require('weflayr');

async function handleRequest(customerId) {
  weflayr_propagate('customer_id', customerId);

  // Both calls below will carry customer_id automatically
  await client.chat.completions.create({ model: 'gpt-4o', messages: [...] });
  await client.chat.completions.create({ model: 'gpt-4o', messages: [...] });
}
from weflayr import weflayr_propagate

def handle_request(customer_id: str):
    weflayr_propagate("customer_id", customer_id)

    # Both calls below will carry customer_id automatically
    client.chat.completions.create(model="gpt-4o", messages=[...])
    client.chat.completions.create(model="gpt-4o", messages=[...])

Tag priority (highest wins): __weflayr_tags > weflayr_propagate > default_tags.

Note: weflayr_propagate mutates global state. In a multi-tenant server, prefer setting customer_id via per-call __weflayr_tags instead, or reset the propagated value between requests.


methods

Whitelist of call paths to instrument. Only methods listed here are intercepted — all others pass through untouched.

methods: [
  { call: 'chat.completions.create' },
  {
    call: 'audio.speech.create',
    middleware: (args, response) => ({ char_count: args?.input?.length ?? 0 }),
  },
]
"methods": [
    {"call": "chat.completions.create"},
    {
        "call": "audio.speech.create",
        "middleware": lambda args, resp: {"char_count": len(args.get("input") or "")},
    },
]
Field Type Description
call string Dot-separated path on the instrumented object (e.g. chat.completions.create)
middleware function Optional. (args, response) => object. Runs on both before and after events. response is null on before events. The returned object is merged into the event payload.