Convert WAV to FLAC
To convert WAV to FLAC, send one POST to /v1/audio-convert with the WAV source and "to": "flac" in the body. Left out, "to" falls back to its default "mp3", so a FLAC request has to send it. Each call costs $0.003 in USDC on Base via x402, with no account and no API key. The source file can be up to 100 MB and 60 min (3,600 s) long.
- Endpoint
POST /v1/audio-convert- Price
- $0.003 per call
- Service
- audio-convert
01Limits
| Limit | Value |
|---|---|
| Largest source file | 100 MB (104,857,600 bytes) |
| Longest input | 60 min (3,600 s) |
| Timeout | 94 s |
| Source formats | AIFF, AVI, FLAC, MKV, MP3, MP4, Ogg, WAV |
| Output formats | AAC, FLAC, MP3, Opus, WAV |
02Example
A real WAV to FLAC run of audio-convert.
POST /v1/audio-convert
content-type: application/json
payment-signature: <base64 x402 payload>
{
"url": "https://grist.tools/samples/av/waveform-beeps.wav",
"to": "flac"
}200 OK
payment-response: <base64 settlement receipt>
{
"source_url": "https://grist.tools/samples/av/waveform-beeps.wav",
"bytes": 32044,
"source_container": "wav",
"format": "flac",
"bitrate_kbps": null,
"sample_rate": null,
"audio_bytes": 14153,
"audio_base64": "ZkxhQwAAACICQAJAAAAAAASVAfQA8AAAAAAAAAAAAAAAAAAAAAAAAAAABAAADgYA..."
}Source file: av/waveform-beeps.wav, 31.3 KB (32,044 bytes). Two-second mono 16-bit PCM WAV at 8 kHz: three 0.4 s 500 Hz triangle-wave beeps at rising level separated by silence, generated from integer arithmetic. The recorded run returned 13.8 KB (14,153 bytes) of FLAC, 44% of the source size, with the source read as the wav container. Decoded, the FLAC in audio_base64 opens with 66 4C 61 43 00 00 00 22 02 40 02 40 (ASCII fLaC). Recorded with ffmpeg 8.1.2.
In the sample itself: The RIFF header counts 32,036 bytes after itself, and the fmt chunk, in its own field order, declares audio format 1 (integer PCM), 1 channel, 8,000 Hz, 16,000 bytes per second, a block align of 2 bytes and 16 bits per sample. The data chunk right after it holds 32,000 bytes of samples, 2 s at that rate. In the returned FLAC: its 34-byte STREAMINFO block, in its own field order, declares blocks of 576 samples, a largest frame of 1,173 bytes, 8,000 Hz, 1 channel, 16 bits per sample and a total sample count of 0, which the format reserves for a length the encoder did not write back. Its MD5 signature of the decoded audio is all zeros, the value for a signature that was not computed. The next metadata block is VORBIS_COMMENT, 14 bytes long.
03Format notes
WAV as a source
WAV is a RIFF file whose form type at byte eight reads WAVE, and it usually carries uncompressed PCM samples. Grist requires both markers, which keeps WebP images and AVI video, the other RIFF users, out of the audio path. Because a WAV holds audio alone, video-thumbnail and subtitle-extract refuse it as a container without a picture or caption stream, and only audio-convert accepts it. Before any sample is encoded, the length of the first audio stream is measured, first from the container header and, when that is missing or doubtful, by scanning packet timestamps; a file whose duration cannot be established is refused instead of being encoded blind. Since PCM is already decoded audio, the converter reads the samples directly rather than undoing another codec before the destination encoder runs.
FLAC as a target
FLAC output is produced by ffmpeg's flac codec and flac muxer, streamed to a pipe rather than a temporary file. This destination is lossless, so a bitrate_kbps value is rejected instead of silently ignored. The caller may pin a sample_rate from the closed set; otherwise ffmpeg picks, normally the rate of the input. Before encoding starts the duration is checked, then only the first audio stream is mapped, video is discarded, and metadata and chapters are removed. Bit-exact flags make the output reproducible with the pinned ffmpeg. From a PCM source the result is normally smaller, and at the source rate the samples are preserved. From a lossy source it grows instead, because the lossless encoder stores every decoded sample, artefacts included, and cannot recover what the earlier compression removed.
04Errors
| Code | HTTP |
|---|---|
invalid_input | 400 |
blocked_target | 403 |
unreachable_target | 424 |
upstream_timeout | 424 |
unsupported_content_type | 415 |
too_large | 413 |
unprocessable | 422 |
internal | 500 |
When each is raised, and what it means for payment: /docs/audio-convert.
05Questions
- What does it cost to convert WAV to FLAC?
- $0.003 per call, paid in USDC on Base via x402.
- How large can the WAV file be?
- Up to 100 MB (104,857,600 bytes), and at most 60 min (3,600 s) of media. Past a limit the call answers too_large (413).
- What happens if the conversion fails?
- The tool answers with a typed JSON error from the errors table. Payment is settled only after the tool has produced its result; a call that fails inside the tool is never settled.