import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}
Dashboard data
Get margin
Get your revenue, AI cost and margin per day, week, month, quarter or year, optionally split by customer.
POST
/
api
/
margin
/
import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}
On an internal project, this route returns a 400
wrong_project_type: use Get performance instead.customer only when group_by is set. Its risk_status is one of "healthy", "watch", "at_risk", "unprofitable", or "unknown" when there is no revenue to compute a margin from.
Parameters
Passed in the request body.string
required
Start of the period, inclusive.
YYYY-MM-DD.string
End of the period, inclusive. Defaults to today.
YYYY-MM-DD.string
default:"day"
One row per period;
"all" collapses the whole date range into a single row (per group_by, if set). One of day, week, month, quarter, year or all.string
Split each period into one row per customer. Omit for one row per period. Only
customer.string[]
Restrict to these customers. Omit for every customer. See Get customers.
string[]
Restrict the cost to these call names. Omit for every call. Revenue is not narrowed. See Get calls.
string[]
Restrict to the customers who used any of these feature tags in the period: the other customers’ rows are removed.
boolean
default:"false"
Apply free AI credits discounts to
cost.integer
default:"100"
Number of rows per page. Max
1000.string
The route is paginated: pass the previous page’s
next_cursor, as is, to get the next page. has_more says whether another page exists.import weflayr
from weflayr.openapi.models import MarginInput
client = weflayr.client() # reads WEFLAYR_API_KEY
client.get_margin(body=MarginInput.from_dict({
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"],
}))
const weflayr = require('weflayr');
const client = weflayr.client(); // reads WEFLAYR_API_KEY
await weflayr.api.getMargin({
client,
throwOnError: true,
body: {
dateFrom: '2026-06-01',
aggregate: 'week',
groupBy: 'customer',
customers: ['c_123', 'c_456'],
},
});
curl -X POST https://app.weflayr.com/api/margin/ \
-H "Authorization: Bearer $WEFLAYR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"date_from": "2026-06-01",
"aggregate": "week",
"group_by": "customer",
"customers": ["c_123", "c_456"]
}'
{
"rows": [
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_123", "revenue": 1200.5, "cost": 420.0, "margin": 780.5, "margin_pct": 65.02, "risk_status": "healthy"},
{"date_from": "2026-06-01", "date_to": "2026-06-07", "customer": "c_456", "revenue": 800.0, "cost": 950.0, "margin": -150.0, "margin_pct": -18.75, "risk_status": "unprofitable"}
],
"next_cursor": null,
"has_more": false
}