Skip to main content
The gateway is the recommended way to send your calls: one change of base URL, no instrumentation, and your calls can then follow a routing strategy. Use the SDK below when your calls must keep going to your providers directly.
1

Get your API key

Create an API key with the Management scope in API keys. Either expose it as the WEFLAYR_API_KEY environment variable, or pass it directly to autoInstrument() in the next step.
.env
2

Install and instrument

Pick the AI provider SDK you use, install it with its instrumentation package, then call autoInstrument() / auto_instrument() once at startup. Frameworks that call these SDKs underneath (LangChain, LlamaIndex…) are covered too.
Install:
Instrument:
Every parameter of autoInstrument() / auto_instrument() is listed in the Python and Node.js SDK references.
Use mask to redact personal data (emails, card numbers, names) before it leaves your process. Your callback receives the span attributes right before export, and what it returns is what Weflayr stores. Returning null keeps the attributes unchanged; throwing an error drops all of them.
3

Add metadata to your LLM calls for finer analysis

Wrap your code in propagateMetadata / propagate_metadata: every LLM call made inside, including nested ones, carries its feature_name and customer_name, so the dashboard breaks your cost down per feature and per customer (e.g. AI Margin or AI Cost).
Every parameter, and the decorator form, is in the Python and Node.js SDK references.When one feature run spans several services, pass them the same feature_run_uuid: see One feature run across several services, which works the same with telemetry.
4

Flush before exit (short-lived runtimes only)

In long-running servers, spans are flushed automatically. In short-lived runtimes (Lambda, scripts, edge functions), call flush() before exit so the final spans reach Weflayr.
5

See your calls

Your calls now show on the Overview, and can be benchmarked.

Examples

Multiple AI providers

autoInstrument() accepts an array of providers, so one call wires both up; subsequent propagateMetadata() blocks tag every LLM call inside them regardless of which provider runs.

Install

Setup

Use

propagateMetadata wraps an entire request handler. Both LLM calls inside, regardless of provider, are stamped with the same customer_name and feature_name.
In your dashboard, both spans land under the same customer_name + feature_name, but the provider field (auto-detected) is openai for the first and anthropic for the second.

AI framework

AI frameworks like LangChain, LlamaIndex or Haystack call the underlying provider SDK (OpenAI, Anthropic, …) so the OpenTelemetry instrumentation for that provider catches every call your chain makes, transparently. You don’t need a framework-specific instrumentation. The example below uses LangChain, but the same approach works with any framework that calls an instrumented provider. This example also turns on exportMode: 'immediate', suitable for short-lived runtimes (Lambda, edge functions, scripts) where you don’t want to risk losing buffered spans on exit.

Install

Setup

Use

A simple RAG-style chain: retrieve context, then ask the LLM. Decorate the feature function with propagateMetadata / propagate_metadata: every instrumented call it makes (here the OpenAI call inside .invoke(...)) is stamped with the metadata, and each invocation gets a fresh correlation id.
The same pattern works for any LangChain construct that ultimately calls an instrumented provider: chains, agents, runnables, LCEL pipelines. If the chain makes several LLM calls (e.g. a tool-calling agent loop), every call inside the decorated function carries the same customer_name and feature_name, so the dashboard can correlate them as one logical request. The decorator fixes its metadata at decoration time; when a value varies per request (a per-call customer_name, say), use the inline form instead (weflayr.propagateMetadata(options, fn) in JS, or with weflayr.propagate_metadata(...): in Python).