MCPcopy Create free account
hub / github.com/TanStack/ai / transformResponse

Method transformResponse

packages/ai-fal/src/adapters/audio.ts:113–149  ·  view source on GitHub ↗
(
    response: Result<OutputType<TModel>>,
  )

Source from the content-addressed store, hash-verified

111 }
112
113 private transformResponse(
114 response: Result<OutputType<TModel>>,
115 ): AudioGenerationResult {
116 const data = response.data as Record<string, unknown>
117
118 // fal returns { audio: { url, content_type } } or { audio_url: string }
119 let audioUrl: string | undefined
120 let contentType: string | undefined
121
122 if (
123 data['audio'] &&
124 typeof data['audio'] === 'object' &&
125 'url' in data['audio']
126 ) {
127 const audioObj = data['audio'] as { url: string; content_type?: string }
128 audioUrl = audioObj.url
129 contentType = audioObj.content_type
130 } else if (typeof data.audio_url === 'string') {
131 audioUrl = data.audio_url
132 }
133
134 if (!audioUrl) {
135 throw new Error('Audio URL not found in fal audio generation response')
136 }
137
138 const usage = buildFalUsage(takeBillableUnits(response.requestId))
139
140 return {
141 id: response.requestId || this.generateId(),
142 model: this.model,
143 audio: {
144 url: audioUrl,
145 contentType: deriveAudioContentType(contentType, audioUrl),
146 },
147 ...(usage ? { usage } : {}),
148 }
149 }
150}
151
152export function falAudio<TModel extends FalModel>(

Callers 1

generateAudioMethod · 0.95

Calls 4

generateIdMethod · 0.95
buildFalUsageFunction · 0.90
takeBillableUnitsFunction · 0.90
deriveAudioContentTypeFunction · 0.90

Tested by

no test coverage detected