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.
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
Install and instrument
Pick the AI provider SDK you use, install it with its instrumentation package, then call Every parameter of
autoInstrument() / auto_instrument() once at startup. Frameworks that call these SDKs underneath (LangChain, LlamaIndex…) are covered too.- Anthropic
- OpenAI
- AWS Bedrock
- Google Vertex AI
- Other
Install:Instrument:
autoInstrument() / auto_instrument() is listed in the Python and Node.js SDK references.Redact personal data with mask
Redact personal data with mask
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.Add metadata to your LLM calls for finer analysis
Wrap your code in 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
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).feature_run_uuid: see One feature run across several services, which works the same with telemetry.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.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.
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 onexportMode: '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 withpropagateMetadata / 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.
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).
Google Vertex AI