Build

Embeddings, images, audio, rerank and video.

Every modality on the same key, the same balance and the same receipts.

On this page

Every modality is paid the two ways chat is. With no account, send the request to the same path under /x402 and pay per request in USDF; see Endpoints paid per request. With a key, it is held, charged on what the provider reports, and receipted against the balance. The samples on this page use a key.

The TypeScript samples use top-level await, so Node runs them only as a module: save one as a .mjs or .mts file, or set "type": "module" in package.json.

The models that serve each one now, and what each is billed per, read live from GET /v1/models:

ModalityEndpointBilled perModels
EmbeddingsPOST /v1/embeddings
ImagesPOST /v1/images/generations, /images/edits
SpeechPOST /v1/audio/speech
TranscriptionPOST /v1/audio/transcriptions
RerankPOST /v1/rerank
VideoPOST /v1/videos/generations
MusicPOST /v1/audio/music

Privacy asks work as on chat: provider.zdr, provider.data_collection and provider.private. On a multipart endpoint, send provider as a JSON string form field.

POST /v1/embeddings turns text into vectors.

ParameterTypeRequiredNotes
modelStringYesAn embedding model.
inputString or arrayYesUp to 1,024 (fewer on some models).
encoding_formatStringNofloat or base64. The SDKs' default, base64, is honoured.
dimensionsIntegerNoWhere the model supports it.

The hold is one token per UTF-8 byte of the input. The charge is the provider's prompt_tokens.

Embed two texts

curl https://api.usdf.fi/v1/embeddings \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "bge-base-en-v1.5",
    "input": ["The first text", "The second text"]
  }'

Response, trimmed

{
  "object": "list",
  "data": [{ "object": "embedding", "index": 0, "embedding": [ … ] }, … ],
  "model": "bge-base-en-v1.5",
  "usage": { "prompt_tokens": …, "total_tokens": … },
  "receipt": { "request_id": "<request_id>", "cost": { … }, … }
}

Generate

POST /v1/images/generations takes JSON.

ParameterTypeRequiredNotes
modelStringYesAn image model.
promptStringYesWhat to draw.
nIntegerNo1 to 4 images. Default 1.
sizeStringNoWxH, 128 to 1920 pixels a side. Default 1024x1024.
response_formatStringNob64_json only.

Generate an image

curl https://api.usdf.fi/v1/images/generations \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "sdxl-turbo",
    "prompt": "A lighthouse at dawn, watercolor",
    "n": 1,
    "size": "1024x1024",
    "response_format": "b64_json"
  }'

Response, trimmed

{
  "created": …,
  "data": [{ "b64_json": "…" }],
  "model": "sdxl-turbo",
  "receipt": { "request_id": "<request_id>", "billed": { … }, "cost": { … }, … }
}

Edit

POST /v1/images/edits takes multipart: image and prompt (both required), mask, model, n and size. Models whose endpoints include image_edits serve it.

Edit an image

curl https://api.usdf.fi/v1/images/edits \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -F model=flux-2-dev \
  -F prompt="The same scene at night" \
  -F image=@input.png

Images are billed per image unit: 1024 x 1024 output pixels at the model's default steps, measured from the bytes returned. The response carries created, data, model and the receipt.

A bad size gets 400 invalid_size. A body that is not multipart gets not_multipart, and one that cannot be parsed bad_multipart.

POST /v1/audio/speech turns text into audio.

ParameterTypeRequiredNotes
modelStringYesA speech model.
inputStringYesUp to the model's context in characters (10,000 for kokoro-82m). Longer gets 400 input_too_long.
voiceStringNoOne of the model's own voices: the names depend on the model. Left out, the model's default voice is used.
response_formatStringNomp3, opus, flac, wav or pcm.
speedNumberNo0.25 to 4.

Speech is billed per million UTF-8 bytes of input. The response body is the audio. The receipt id is in x-request-id and the cost in x-cost-units; the full receipt is at GET /v1/receipts/{id}.

Synthesize speech

curl https://api.usdf.fi/v1/audio/speech \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "kokoro-82m",
    "input": "Hello from USDF.",
    "response_format": "mp3"
  }' \
  -D - --output speech.mp3

POST /v1/audio/transcriptions turns audio into text. It takes multipart.

ParameterTypeRequiredNotes
fileFileYesWAV (PCM or float), FLAC, MP3, or Ogg (Opus or Vorbis). Others get 400 unsupported_audio. Over 4 hours: 400 audio_too_long.
modelStringYesA transcription model.
languageStringNoThe spoken language.
promptStringNoContext for the model.
response_formatStringNojson or text; verbose_json and diarized_json on some models.
temperatureNumberNo0 to 1.
timestamp_granularities[]StringNosegment or word.

The hold is the longest audio the file can decode to. The charge is per minute, from the duration the provider reports.

Transcribe a file

curl https://api.usdf.fi/v1/audio/transcriptions \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -F model=whisper-large-v3-turbo \
  -F file=@meeting.mp3 \
  -F response_format=json

POST /v1/rerank scores documents against a query.

ParameterTypeRequiredNotes
modelStringYesA rerank model.
query or queriesString or arrayYesWhat to rank against.
documentsArrayYesQueries times documents: at most 1,024 pairs.
instructionStringNoUp to 2,048 characters.

Rerank is billed per 1M tokens, on the provider's input_tokens.

Rerank two documents

curl https://api.usdf.fi/v1/rerank \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "llama-nemotron-rerank-vl-1b-v2",
    "query": "How is USDF backed?",
    "documents": [
      "USDF is backed 1:1 by USDG.",
      "The gateway serves many models."
    ]
  }'

Response, trimmed

{
  "scores": [ … ],
  "input_tokens": …,
  "results": [{ "index": 0, "relevance_score": … }, … ],
  "receipt": { "request_id": "<request_id>", "cost": { … }, … }
}

POST /v1/videos/generations starts a job and answers 202 at once. Poll the job, then fetch the clip.

ParameterTypeRequiredNotes
modelStringYesA video model.
promptStringYesUp to the model's context in characters (2,000).
secondsIntegerNoThe clip length. Each model has its own range, and some make one fixed length. Left out, the model's default is used. A length outside the range gets 400 invalid_seconds, and the message names the range.
resolutionStringNoThe model's one resolution (720p for fastwan2.2-ti2v-5b), or left out. size is refused with 400 size_unsupported.
aspect_ratioStringNoOne of the model's own.
imageStringNoA first frame, as a PNG or JPEG data URL, where the model takes one.
negative_promptStringNoWhat to avoid.
seedIntegerNoFor repeatable output.

Make a clip

curl https://api.usdf.fi/v1/videos/generations \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "fastwan2.2-ti2v-5b",
    "prompt": "A paper boat drifting down a river, slow pan",
    "seconds": 5
  }'

# Poll until "status" is "completed" or "failed".
curl https://api.usdf.fi/v1/videos/<id> \
  -H "Authorization: Bearer $USDF_API_KEY"

# The clip, billed on this first fetch. Content-Type says mp4 or webm.
curl https://api.usdf.fi/v1/videos/<id>/content \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -D - --output clip

Response, 202

{
  "id": "<request_id>",
  "status": "queued",
  "seconds": 5,
  "resolution": "720p",
  "aspect_ratio": "…",
  "hold": { "units": "<units>", "usd": "<usd>", "usdf": "<usdf>" },
  "poll": "https://api.usdf.fi/v1/videos/<request_id>",
  "content": "https://api.usdf.fi/v1/videos/<request_id>/content"
}

Poll GET /v1/videos/{id} until status is completed or failed. GET /v1/videos/{id}/content returns the clip as video/mp4 or video/webm. Only the key that made a job reads it.

A clip is billed per second, at the model's one resolution, on its first fetch. One never fetched is billed when it expires, 30 minutes after it was made. A key has at most two unbilled jobs; a third gets 429 too_many_video_jobs. A clip is at most 32 MiB. A gateway restart ends a job unbilled.

Paid per request, the 202 carries a read_token. Read the job with Authorization: Bearer <read_token>.

POST /v1/audio/music makes one track of music from a text prompt. It takes JSON, and the response body is the track itself, as MP3.

ParameterTypeRequiredNotes
modelStringYesA music model.
promptStringYesThe music to make: genre, mood, instruments, tempo and what the song is about. Up to 2,000 characters.
lyricsStringNoThe words to sing, with [verse] and [chorus] marks where wanted. Up to 8,000 characters. Left out, the model writes its own or none.
instrumentalBooleanNoTrue for a track with no vocals. An instrumental track takes no lyrics: send one or the other.
response_formatStringNomp3, the only format served. Any other gets 400 unsupported_format.

The prompt and the lyrics together are at most the model's context in characters (10,000 for acestep-v15-xl-sft). Longer gets 400 input_too_long.

Pick a model

A music model has the modality music and music in its endpoints. GET /v1/models?output_modalities=audio lists them, and so does the catalog. The model fixes the track's length, never the request: a short clip on some, a whole song on others. GET /v1/pricing gives each one's price per track and the length it makes. A model whose may_keep_data is true may keep the request; the samples use one that keeps nothing.

Music is billed per track. The hold is one track at the sheet price, and the charge is that track once its audio arrives. An answer that is not audio is not charged.

Make a track

curl https://api.usdf.fi/v1/audio/music \
  -H "Authorization: Bearer $USDF_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "acestep-v15-xl-sft",
    "prompt": "A calm solo piano piece, slow and warm",
    "instrumental": true,
    "response_format": "mp3"
  }' \
  -D - --output track.mp3

The receipt is in the x-receipt header, as base64url of its JSON. The receipt id is also in x-request-id and the cost in x-cost-units, and the full receipt stays readable at GET /v1/receipts/{id}.

A track the provider has not finished by the gateway's deadline gets 504 upstream_timeout. That answer is JSON, not audio: the error, with a receipt whose status is failed_refunded. The hold is refunded and nothing is charged, so check the status before you save the body. The other errors are in Errors.

Images to edit and audio to transcribe are uploaded as multipart bodies.

  • A body is at most 25 MiB. It is held in memory and never written to disk.
  • A request with no key, or a malformed one, is refused with 401 before its body is read. A larger declared body gets 413.
  • One gateway instance holds eight uploads at a time, two per key. Over that: 429 too_many_uploads with Retry-After.
  • Paid per request, send the multipart body whole both times: the quote is read from the file.

See receipts and verification

Foundry documentation

Confirm it's you

Confirm to continue the action you started.

Checking confirmation options…