npm
The
weflayr package.Changelog
What changed in each release.
Send extra metadata to the gateway
Group the gateway calls of the same feature, and optionally tag their customer and your own dimensions.
Track calls with telemetry only
Record the calls your app makes to Anthropic, OpenAI, Bedrock, Vertex AI and other providers directly.
Call the management API
Read your costs and margin, and push revenue and customer tags.
Install
Requires Node.js 22.15 or later.Reference
Send extra metadata to the gateway
enablePropagateMetadataToGateway
propagateMetadata values in the x-weflayr-metadata header of its gateway requests. Requires the openai package, and setup() to have run.
Parameters
Parameters
string
default:"https://gateway.weflayr.com"
The gateway URL whose requests get the header. Requests to any other host are left unchanged.
Example
Example
propagateMetadata
fn, runs it and returns its result. Without, returns a decorator for a class method, or a wrapper: propagateMetadata(options)(fn). Each call of propagateMetadata (or of a decorated method) is one feature run.
Parameters
Parameters
string
required
The product feature making the call (e.g.
'support-chat').string
The customer the call is made for. It joins your AI cost to your revenue.
Record<string, string | number | boolean>
Your own dimensions to filter on.
string
Records the calls under this run instead of a new one, to group the calls of one run made in several scopes or processes. Create it with
weflayr.createFeatureRunUuid(): 32 lowercase hexadecimal characters.weflayr.AIProviderName
The provider to bill a call recorded by telemetry, when the client on the wire differs from it (e.g. Mistral reached through the OpenAI client). Ignored for gateway calls.
function
Runs this function inside the scope and returns its result.
Example
Example
Track calls with telemetry only
autoInstrument
Parameters
Parameters
Example
Example
setup
Parameters
Parameters
string
A key with the Management scope. Defaults to
WEFLAYR_API_KEY.string
default:"'https://api.weflayr.com'"
Where recorded calls are sent.
object
Tags added to every recorded call.
'batch' | 'immediate'
default:"'batch'"
'immediate' sends each call as soon as it ends, instead of in batches.boolean
default:"true"
Set
false to keep prompts, answers and tool definitions in your process: only tokens, cost and latency are sent.(attributes) => attributes
Receives each call’s attributes and returns the ones to send. Returning
null keeps them unchanged; throwing an error drops all of them.boolean
default:"true"
Set
false to silence the warning written to stderr on each failed export.Example
Example
setCallName
fn, runs it and returns its result; without, returns a decorator. It keeps the enclosing propagateMetadata scope and does not start a new feature run.
Parameters
Parameters
Example
Example
flush
Example
Example
Call the management API
Every management API route, with its SDK method, is listed in Call the management API.client
weflayr.api functions.
Parameters
Parameters
Example
Example