Deployment guide

Kokoro-FastAPI

Overview

Kokoro-FastAPI is an open-source, self-hosted text-to-speech (TTS) server that wraps the compact Kokoro-82M speech model behind an OpenAI-compatible HTTP API. Any client that already speaks the OpenAI audio format can point at your own endpoint and generate natural speech from text, with no per-character cloud bills and no text leaving your VM.

This SecureAnyCloud image runs Kokoro-FastAPI 0.6.0 on Ubuntu 24.04 on Azure. It installs the server from the official CPU container image, pinned to a specific version, and runs it under Docker and systemd.

The Kokoro-82M model, all 68 built-in voices and the language dictionaries are baked into the image, so the server synthesizes speech offline the moment it boots, with no model download. The model runs comfortably on CPU, so no GPU is required.

Secure by default: a per-VM API key and no open endpoint. An open TTS endpoint is a compute-abuse risk, so this image never exposes one. The application binds to the loopback interface only. An nginx reverse proxy on port 80 is the sole public surface, and it requires an OpenAI-style Authorization: Bearer API key on every request except the health check.

A fresh, unique API key is generated on the first boot of every VM. No default or shared key ships in the image, and until first boot completes, every request except /health returns 401.

What you get:

  • Kokoro-FastAPI 0.6.0 (official CPU container), run under Docker and systemd as kokoro-fastapi.service
  • The Kokoro-82M model and 68 built-in voices baked into the image for fully offline synthesis
  • An nginx reverse proxy on port 80 that enforces a per-VM Bearer API key, with the application bound to loopback only
  • A unique API key generated on first boot and written to /root/kokoro-fastapi-credentials.txt (root-only, mode 0600)
  • The OpenAI-compatible /v1/audio/speech endpoint with WAV, MP3, FLAC, Opus, AAC and PCM output, plus /v1/audio/voices
  • 24/7 SecureAnyCloud support

Prerequisites

You need an active Azure subscription, an SSH public key, a VNet with a subnet in the target region, and a subscription to the Kokoro-FastAPI listing on the Azure Marketplace.

Configure network security group (NSG) rules that allow TCP 22 (admin) and TCP 80 (the authenticated API) from the networks you trust.

Recommended VM size: Standard_D2s_v5 (2 vCPU, 8 GB RAM) gives responsive synthesis. The model runs on CPU, and Standard_B2s (2 vCPU, 4 GB) also works for light use. No GPU is required.

1

Deploy from the Azure Portal

  • Open the Kokoro-FastAPI offer on the Azure Marketplace, choose Get It Now, then choose Create.
  • Select your subscription, resource group and region, and choose the Standard_D2s_v5 size.
  • Provide your SSH public key for the azureuser account.
  • In the network security group, allow inbound TCP 22 and TCP 80 from your trusted networks, then create the VM.
2

Deploy from the Azure CLI

# Accept the Marketplace terms once per subscription (required before the first CLI deploy)
az vm image terms accept --urn sac1647283583153:kokoro-fastapi-ubuntu-24-04:default:latest
az vm create \
  --resource-group my-rg \
  --name kokoro-01 \
  --image sac1647283583153:kokoro-fastapi-ubuntu-24-04:default:latest \
  --size Standard_D2s_v5 \
  --admin-username azureuser \
  --generate-ssh-keys \
  --public-ip-sku Standard
3

First boot

On the first boot of every VM, kokoro-fastapi-firstboot.service generates a fresh, unique API key, writes it into the nginx authentication gate and reloads nginx, brings the TTS container up, and writes the key to /root/kokoro-fastapi-credentials.txt. First boot takes under a minute, so wait a moment before you send the first request.

4

Confirm the service is running

SSH in as azureuser. Confirm that Docker, the TTS service and nginx are active and that the health check answers. The health endpoint is intentionally open and needs no key:

systemctl is-active docker kokoro-fastapi nginx curl -s http://127.0.0.1/health

You should see active for each service and {"status":"healthy"} from the health check.

5

Retrieve your per-VM API key

The API key is unique to this VM and is stored in a root-only file:

sudo cat /root/kokoro-fastapi-credentials.txt

The KOKORO_API_KEY value is your Bearer token. Keep it secret. Store it in a shell variable for the next steps. From your own workstation, use the value you just read:

KEY=$(sudo grep '^KOKORO_API_KEY=' /root/kokoro-fastapi-credentials.txt | cut -d= -f2)
6

Verify that the endpoint requires authentication

The speech endpoint rejects an unauthenticated request and accepts an authenticated one. Run both requests to confirm:

KEY=$(sudo grep '^KOKORO_API_KEY=' /root/kokoro-fastapi-credentials.txt | cut -d= -f2)
# No key -> 401 Unauthorized curl -s -o /dev/null -w '%{http_code}\n' -X POST http://127.0.0.1/v1/audio/speech \
  -H 'Content-Type: application/json' \
  -d '{"model":"kokoro","input":"hello","voice":"af_bella","response_format":"wav"}'
# With the per-VM key -> 200 OK curl -s -o /dev/null -w '%{http_code}\n' -X POST http://127.0.0.1/v1/audio/speech \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"model":"kokoro","input":"hello","voice":"af_bella","response_format":"wav"}'

The first call prints 401; the second prints 200.

7

Generate speech

Generate a WAV file from text with the OpenAI-compatible endpoint and your API key:

KEY=$(sudo grep '^KOKORO_API_KEY=' /root/kokoro-fastapi-credentials.txt | cut -d= -f2)
curl -s -X POST http://127.0.0.1/v1/audio/speech \
  -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' \
  -d '{"model":"kokoro","input":"Hello world, this is Kokoro FastAPI running on Azure.","voice":"af_bella","response_format":"wav"}' \
  --output hello.wav file hello.wav

file hello.wav reports a RIFF WAVE audio file. Supported response_format values are wav, mp3, flac, opus, aac and pcm.

8

List the built-in voices

All 68 voices are baked into the image. List them through the authenticated endpoint:

KEY=$(sudo grep '^KOKORO_API_KEY=' /root/kokoro-fastapi-credentials.txt | cut -d= -f2)
curl -s http://127.0.0.1/v1/audio/voices -H "Authorization: Bearer $KEY" \
  | python3 -c "import sys,json; v=json.load(sys.stdin)['voices']; names=[x['id'] if isinstance(x,dict) else x for x in v]; print('voices:',len(names)); print(', '.join(names[:12]))"

The output shows the voice count and a sample of the available voices, for example af_bella, af_heart, af_nicole, am_michael and bf_emma. To combine voices, join their names with + in the voice field, for example af_bella+af_sky.

9

Use it from the OpenAI Python client

Because the API is OpenAI-compatible, you can point the official client at your VM and use your per-VM key. Replace <vm-ip> and <your-key> with your values:

from openai import OpenAI client = OpenAI(base_url="http://<vm-ip>/v1", api_key="<your-key>") with client.audio.speech.with_streaming_response.create( model="kokoro", voice="af_bella", input="Hello from the OpenAI client.", response_format="wav", ) as response: response.stream_to_file("out.wav")
10

Rotate the API key

To issue a new key, edit the nginx gate and reload nginx. The example below shows the approach, so generate your own strong random key:

NEWKEY=$(openssl rand -hex 32)
sudo sed -i "s#\"Bearer .*\" 1;#\"Bearer ${NEWKEY}\" 1;#" /etc/nginx/conf.d/sac-kokoro-key.conf
sudo nginx -t && sudo systemctl reload nginx
# record the new key somewhere safe; update /root/kokoro-fastapi-credentials.txt if you rely on it echo "$NEWKEY"
11

Security recommendations

  • Keep port 80 open only to the clients that need it, using a tightly scoped NSG rule. The endpoint is authenticated, but the model still consumes CPU on every request.
  • Terminate TLS in front of the API so that the Bearer key is never sent in clear text. Add a certificate to nginx, or place the VM behind an Azure Application Gateway or Load Balancer with HTTPS.
  • Treat the contents of /root/kokoro-fastapi-credentials.txt as a secret, and rotate the key (Step 10) if you suspect it was exposed.
  • Keep the OS patched. The image ships fully updated with unattended security upgrades enabled.
12

Support and licensing

Kokoro-FastAPI is free, open-source software distributed under the Apache License 2.0. This image bundles Kokoro-FastAPI unmodified. Its license governs your use of the server, and the Kokoro model and voices are governed by their respective licenses.

SecureAnyCloud images include 24/7 support. If you need help deploying or configuring Kokoro-FastAPI on Azure, contact us.

Deploy on Azure

Find this image on the Azure Marketplace and deploy in minutes.

Need Help?

Email sales@secureanycloud.com and our team will help you get up and running.

Deploy on Azure

Launch Kokoro-FastAPI 0.6.0 on Ubuntu 24.04 LTS on Azure with 24/7 support from SecureAnyCloud.

View this image

Need Help?

Our support team is available 24/7.

sales@secureanycloud.com

Deploy on Azure