Function API

Function's dictation as an API. Send speech, get back text: polished the way Function's keyboard writes it, or every word as it was said.

Quickstart

  1. Sign in to the dashboard, add a payment method, and create an API key.
  2. Send a recording:
    curl https://functionvoice.ai/api/v1/audio/transcriptions \
      -H "Authorization: Bearer $FUNCTION_API_KEY" \
      -F model=function/dictate-1.2 \
      -F file=@recording.m4a
  3. Get the text back:
    {
      "text": "Can you send the deck to Priya by Friday?",
      "usage": { "seconds": 3.82, "cost": 0.0020833333 }
    }

Base URL. https://functionvoice.ai/api/v1

Try every parameter without writing code in the dashboard's playground. Its Overview page has a prompt to paste into your coding agent that integrates the API for you.

Authentication and keys

Send your key as a bearer token on every request:

Authorization: Bearer fn_live_…

Create keys in the dashboard. A key is shown once, when it is made: we keep only a fingerprint of it, so it can't be shown again or recovered. Keep keys on your server. Never ship one in an app or a web page, and never put one in a URL. A revoked key stops working at once.

Each key can carry its own rules, all enforced by the API:

Models

The method is the model. Both take the same request and give the same answer.

ModelWhat it returns
function/dictate-1.2Speech to polished text, as Function's keyboard types it: fillers and false starts gone, self-corrections resolved, lists and paragraphs laid out, in the speaker's own voice. It formats for what you're writing, keeps every detail, and never answers or carries out what was said.
function/transcribe-1.2Speech to text: every word as it was said, punctuated, with the names and terms you send spelled right.

function/dictate and function/transcribe always name the latest version. Pin the version to keep the same behavior.

GET /api/v1/models lists them (?output_modalities=transcription filters), each with its price: pricing.audio per second and pricing.audio_per_hour, in dollars.

Transcriptions

POST /api/v1/audio/transcriptions, as multipart/form-data with the file, or as JSON with the audio in base64.

Multipart

curl https://functionvoice.ai/api/v1/audio/transcriptions \
  -H "Authorization: Bearer $FUNCTION_API_KEY" \
  -F model=function/transcribe-1.2 \
  -F file=@recording.wav \
  -F language=en \
  -F 'keyterms[]=Priya' -F 'keyterms[]=Q3 roadmap'

JSON

curl https://functionvoice.ai/api/v1/audio/transcriptions \
  -H "Authorization: Bearer $FUNCTION_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "function/dictate-1.2",
    "input_audio": { "data": "'"$(base64 < recording.wav)"'", "format": "wav" },
    "language": "en",
    "keyterms": ["Priya", "Q3 roadmap"]
  }'

Python

import os, requests

with open("recording.m4a", "rb") as audio:
    answer = requests.post(
        "https://functionvoice.ai/api/v1/audio/transcriptions",
        headers={"Authorization": f"Bearer {os.environ['FUNCTION_API_KEY']}"},
        data={"model": "function/dictate-1.2", "language": "en"},
        files={"file": audio},
    ).json()
print(answer["text"])

Node

import { readFile } from "node:fs/promises";

const body = new FormData();
body.append("model", "function/dictate-1.2");
body.append("file", new Blob([await readFile("recording.m4a")]), "recording.m4a");
const answer = await fetch("https://functionvoice.ai/api/v1/audio/transcriptions", {
  method: "POST",
  headers: { Authorization: `Bearer ${process.env.FUNCTION_API_KEY}` },
  body,
}).then((response) => response.json());
console.log(answer.text);

Request fields

FieldTypeWhat it is
modelstring, requiredfunction/dictate-1.2 or function/transcribe-1.2.
filefile (multipart)The recording. Its format is read from the file itself.
input_audioobject (JSON)data, the audio as base64 (raw bytes, not a data URI), and format: wav, m4a or pcm.
languagestringThe language spoken, as an ISO-639-1 code such as en or es. English if you leave it out. Dictate keeps the language that was spoken.
keytermsarray of stringsNames and terms to spell exactly as given: people, products, jargon. Up to 1,000, each up to 100 characters. In multipart, repeat keyterms[].
sample_rateintegerFor pcm only: its rate in Hz, 8000 to 48000. 16000 if you leave it out.
response_formatstringjson (the default) or verbose_json.

prompt, temperature, timestamp_granularities, provider, user and session_id are accepted and ignored, so a client written for this common shape works unchanged.

Audio

Up to 10 minutes and 24 MB a request. MP3, FLAC, Ogg and WebM are refused with unsupported_audio_format.

Response

{
  "text": "Can you send the deck to Priya by Friday?",
  "usage": { "seconds": 3.82, "cost": 0.0020833333 }
}
FieldWhat it is
textThe text: polished for Dictate, as said for Transcribe. Empty when nothing was said.
usage.secondsThe recording's length.
usage.costWhat this request cost, in dollars (see Pricing).

With "response_format": "verbose_json", the answer also has task, language (the language heard, when known) and duration.

Each answer's X-Function-Generation-Id header names the request. It is the id in the dashboard's request list; quote it when you report a problem.

Streaming

Stream audio while the user speaks, and get the text a moment after they stop. Open a WebSocket to the same path, with the model in the URL and your key in the Authorization header:

wss://functionvoice.ai/api/v1/audio/transcriptions?model=function/dictate-1.2&language=en

The URL also takes sample_rate and repeated keyterms. A client that can't set headers on a WebSocket, as in a browser, can send the key as two subprotocols instead, function-api and bearer. followed by the key; the server answers with function-api. Never put a key in a page you ship to others.

Then:

  1. The server sends session.created.
  2. Optionally, before any audio, send session.update with keyterms, language or sample_rate. The server answers session.updated.
  3. Send audio as it is recorded: binary messages of raw 16-bit little-endian mono PCM (16 kHz unless sample_rate says), or input_audio_buffer.append events with the PCM as base64. Every 100 to 250 ms is a good pace.
  4. When the speaker stops, send input_audio_buffer.commit. The server sends input_audio_buffer.committed, then transcript.text.done with the text and the usage, and closes the socket.
→ {"type": "session.update", "session": {"keyterms": ["Priya"], "sample_rate": 16000}}
← {"type": "session.updated", "session": {"id": "gen-…", "model": "function/dictate-1.2", "input_audio_format": "pcm16", "sample_rate": 16000, …}}
→ (binary PCM) (binary PCM) …
→ {"type": "input_audio_buffer.commit"}
← {"type": "input_audio_buffer.committed", "audio_seconds": 3.82}
← {"type": "transcript.text.done", "text": "Can you send the deck to Priya by Friday?", "usage": {"seconds": 3.82, "cost": 0.0020833333}}

Node

import WebSocket from "ws";

const socket = new WebSocket("wss://functionvoice.ai/api/v1/audio/transcriptions?model=function/dictate-1.2", {
  headers: { Authorization: `Bearer ${process.env.FUNCTION_API_KEY}` },
});
socket.on("open", () => {
  microphone.on("data", (pcm) => socket.send(pcm));            // 16-bit mono, 16 kHz
  microphone.on("end", () => socket.send(JSON.stringify({ type: "input_audio_buffer.commit" })));
});
socket.on("message", (data) => {
  const event = JSON.parse(data.toString());
  if (event.type === "transcript.text.done") console.log(event.text);
  if (event.type === "error") console.error(event.error.message);
});

Python

import asyncio, json, os, websockets

async def dictate(chunks):
    async with websockets.connect(
        "wss://functionvoice.ai/api/v1/audio/transcriptions?model=function/dictate-1.2",
        additional_headers={"Authorization": f"Bearer {os.environ['FUNCTION_API_KEY']}"},
    ) as socket:
        async for chunk in chunks:          # bytes of 16-bit mono PCM at 16 kHz
            await socket.send(chunk)
        await socket.send(json.dumps({"type": "input_audio_buffer.commit"}))
        async for message in socket:
            event = json.loads(message)
            if event["type"] == "transcript.text.done":
                return event["text"]
            if event["type"] == "error":
                raise RuntimeError(event["error"]["message"])

A stream checks the key and its rules, the model and the payment method before it opens: a refusal is an HTTP error, as for a POST. After it opens, a problem is an error event in the same shape as an error's body. One that ends the stream is followed by a close. A stream with no message for 20 seconds before its commit is closed with timeout. A stream is billed like a file: its audio, at least 10 seconds.

Errors

An error has the HTTP status, a message to read, and a type to act on:

{
  "error": {
    "code": 403,
    "message": "This API key has reached its spending limit of $25.00 this month (UTC).",
    "metadata": { "error_type": "spend_limit", "limit_source": "key_month" }
  }
}
Statuserror_typeMeaning
400invalid_requestA field is missing or wrong. The message says which.
400unsupported_audio_formatNot WAV, M4A or PCM.
401missing_api_key, invalid_api_keyNo key, or one that's wrong or revoked.
401expired_api_keyThe key is past its expiry.
402payment_requiredAdd a payment method in the dashboard.
403forbiddenThe key isn't allowed to use this model.
403ip_not_allowedThe request came from outside the key's IP allowlist.
403spend_limitThe key reached its spending limit. metadata.limit_source says which.
404not_foundNo such endpoint or model.
405method_not_allowedThe wrong method for the endpoint.
408timeoutA stream went quiet before its commit.
413payload_too_largeOver 10 minutes or 24 MB.
429rate_limitedOver 120 requests a minute for the key. Wait for Retry-After.
500internal_errorSomething went wrong on our side. Try again.
502transcription_failedThe audio couldn't be transcribed this time. Try again. You aren't charged.
503unavailableThe service is briefly unavailable. Try again after Retry-After.

Pricing

ModelPer hour of audio
function/dictate-1.2$0.75
function/transcribe-1.2$0.75

Limits

Your data. We don't keep your audio or the text. The dashboard keeps each request's time, length, status and cost, for your usage.

Key info

GET /api/v1/key: the key's name, what it has spent in dollars (in all, today, this week and this month, in UTC), its spending limit and what is left of it, its permissions and expiry, and its rate limit.

{
  "data": {
    "label": "Production",
    "usage": 4.21, "usage_daily": 0.12, "usage_weekly": 0.95, "usage_monthly": 4.21,
    "limit": 25, "limit_remaining": 20.79, "limit_reset": "monthly",
    "expires_at": null, "permissions": ["dictate", "transcribe"],
    "is_free_tier": false, "is_management_key": false,
    "rate_limit": { "requests": 120, "interval": "1m" }
  }
}