# Kokoro-FastAPI

> Serve the Kokoro-82M voice model behind an OpenAI-compatible speech endpoint

- Category: Multimodal Generation / Audio, Music & Voice
- Language: Python
- Licence: Apache-2.0
- Repository: https://github.com/remsky/Kokoro-FastAPI
- Canonical page: https://ai-tldr.dev/tools/kokoro-fastapi/

## In short

Kokoro-FastAPI is Serve the Kokoro-82M voice model behind an OpenAI-compatible speech endpoint. It sits in the Audio, Music & Voice category of the Multimodal Generation tools and is open-source, written in Python and licensed Apache-2.0. To get started: run the CPU image.

## Overview

Kokoro-FastAPI, also published as FastKoko, wraps the Kokoro-82M text-to-speech model in a FastAPI server that speaks the OpenAI speech API. That single design decision is the point of the project: any client already written against OpenAI's `audio.speech` endpoint — the official Python library included — can be pointed at `http://localhost:8880/v1` with a throwaway API key and start generating audio from a local model instead of a hosted one.

The images ship with the model baked in and cover the hardware people actually have: a CPU image for laptops and CPU-only servers, NVIDIA CUDA images (cu126 by default, cu128 for RTX 50-series/Blackwell, and an arm64 build for Jetson and GH200), an experimental AMD ROCm image, and a native Apple Silicon MPS path that runs directly through uv rather than Docker. A `docker compose` setup and a direct uv run are both documented for people who want to build rather than pull.

On top of plain synthesis it exposes the pieces that longer-form work needs: multi-speaker generation and weighted voice mixing (a voice can be written as `af_sky+af_bella`), SSML, per-word or per-chunk timestamped captions, phoneme endpoints in both directions, custom voicepack generation through the companion Inno Clone-Tuner project, and an optional built-in web UI with read-along. It supports English (US and GB), Spanish, French, Hindi, Italian, Japanese, Brazilian Portuguese and Mandarin Chinese, and is used as the TTS backend by a long list of community projects — Home Assistant add-ons, audiobook generators, SillyTavern and Open WebUI among them.

## What it does

- OpenAI-compatible /v1 speech endpoint — existing OpenAI client code works unchanged against a local Kokoro-82M
- Prebuilt multi-platform images with models included: CPU, NVIDIA CUDA (cu126 / cu128 / arm64), and experimental AMD ROCm; Apple Silicon MPS supported when run directly via uv
- Inline multi-speaker generation and voice mixing with weighted combinations and aliasing, plus SSML support
- Per-word or per-chunk timestamped caption generation, and phoneme endpoints that convert text to phonemes or phonemes to audio
- Custom voicepack generation via the Inno Clone-Tuner companion project
- Optional integrated web UI with read-along for long generations, served alongside the interactive API docs

## Getting started

The quickest path is a single docker run with a prebuilt image — the models are baked in. Pin a release tag rather than :latest for anything you depend on.

1. Run the CPU image

   For a laptop or a CPU-only server. The API comes up on port 8880.

```bash
docker run -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-cpu:latest
```

2. Or run on an NVIDIA GPU

   The default GPU tag ships cu126 (GTX 900-series through RTX 40). For RTX 50-series / Blackwell use the cu128 tag instead; the same default tag covers arm64 Jetson and GH200.

```bash
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest
# RTX 50-series / Blackwell
docker run --gpus all -p 8880:8880 ghcr.io/remsky/kokoro-fastapi-gpu:latest-cu128
```

3. Generate speech with the OpenAI client

   Point base_url at your server and pass any string as the API key. The voice can be a single voicepack or a combination.

```python
from openai import OpenAI

client = OpenAI(
    base_url="http://localhost:8880/v1", api_key="not-needed"
)

with client.audio.speech.with_streaming_response.create(
    model="kokoro",
    voice="af_sky+af_bella", #single or multiple voicepack combo
    input="Hello world!"
  ) as response:
      response.stream_to_file("output.mp3")
```

4. Open the UI and the docs

   The server exposes interactive API documentation and an optional web interface on the same port.

```text
# API docs:      http://localhost:8880/docs
# Web interface: http://localhost:8880/web
```

5. Build from source instead

   Clone the repo and bring up the compose stack for your hardware, or run directly through uv for hot-reload and native Apple Silicon acceleration.

```bash
git clone https://github.com/remsky/Kokoro-FastAPI.git
cd Kokoro-FastAPI
cd docker/gpu   # or docker/cpu, or docker/rocm
docker compose up --build
```

## When to use it

- Swap a paid hosted TTS API for a local model without touching client code, by repointing an existing OpenAI speech integration at localhost
- Generate long-form narration — audiobooks, read-along documents — where per-chunk timestamps and hours of throughput matter more than a single short clip
- Give a self-hosted assistant, Home Assistant install or chat UI a voice, using the community integrations the project already documents
- Build a custom voice with the Clone-Tuner companion and serve it through the same endpoint as the stock voicepacks
