//native
// Get your Strale wallet balance.
// Useful in flows to check remaining credits before executing paid capabilities.
//
// Strale uses a prepaid wallet model — top up via Stripe, then capabilities
// deduct from your balance on each execution.
// https://strale.dev
type Strale = {
api_key: string;
base_url?: string;
};
export async function main(strale: Strale) {
const baseUrl = strale.base_url ?? "https://api.strale.io";
const response = await fetch(`${baseUrl}/v1/balance`, {
method: "GET",
headers: {
"Authorization": `Bearer ${strale.api_key}`,
},
});
if (!response.ok) {
const error = await response.json().catch(() => ({ message: response.statusText }));
throw new Error(
`Strale API error (${response.status}): ${(error as any).error?.message ?? (error as any).message ?? "Unknown error"}`
);
}
const data = await response.json() as {
balance_cents: number;
currency: string;
};
return {
balance_cents: data.balance_cents,
balance: `€${(data.balance_cents / 100).toFixed(2)}`,
currency: data.currency ?? "EUR",
};
}
export async function main(x: string) {
return x
}Submitted by hugo989 7 days ago