MCPcopy Index your code
hub / github.com/simstudioai/sim / fetchFalAIBillingEvent

Function fetchFalAIBillingEvent

apps/sim/lib/tools/falai-pricing.ts:84–119  ·  view source on GitHub ↗
(
  apiKey: string,
  requestId: string
)

Source from the content-addressed store, hash-verified

82}
83
84async function fetchFalAIBillingEvent(
85 apiKey: string,
86 requestId: string
87): Promise<FalAIBillingEvent | undefined> {
88 const url = new URL('https://api.fal.ai/v1/models/billing-events')
89 url.searchParams.set('request_id', requestId)
90 url.searchParams.set('limit', '1')
91
92 let response: Response
93 try {
94 response = await fetch(url, {
95 headers: {
96 Authorization: `Key ${apiKey}`,
97 },
98 })
99 } catch (error) {
100 logger.warn('Failed to fetch Fal.ai billing event', {
101 requestId,
102 error: getErrorMessage(error, 'Unknown error'),
103 })
104 return undefined
105 }
106
107 if (!response.ok) return undefined
108
109 const data = await response.json().catch((error) => {
110 logger.warn('Failed to parse Fal.ai billing event response', {
111 requestId,
112 error: getErrorMessage(error, 'Unknown error'),
113 })
114 return undefined
115 })
116 if (!isRecordLike(data) || !Array.isArray(data.billing_events)) return undefined
117
118 return data.billing_events.map(parseBillingEvent).find(Boolean)
119}
120
121async function estimateFalAICallCost(
122 apiKey: string,

Callers 1

getFalAICostMetadataFunction · 0.85

Calls 4

getErrorMessageFunction · 0.90
isRecordLikeFunction · 0.90
setMethod · 0.65
warnMethod · 0.65

Tested by

no test coverage detected