Railway

Deploy Kokoro TTS API | (Just Updated) OpenAI-Compatible Voice, Hobby Plan Recommended

OpenAI-compatible TTS API. Needs 1.5GB RAM, Hobby plan or above.

Deploy Kokoro TTS API | (Just Updated) OpenAI-Compatible Voice, Hobby Plan Recommended

Just deployed

Deploy and Host Kokoro-FastAPI on Railway

Kokoro-FastAPI is a Dockerized FastAPI wrapper for the Kokoro-82M text-to-speech model. It provides OpenAI-compatible endpoints for multi-language speech synthesis with support for multiple audio formats, streaming, and voice combinations.

Resource Requirements — Read Before Deploying

This template runs the PyTorch build of Kokoro and needs at least 1.5 GB of RAM. Measured on the current image: ~1.05 GB resident once the model has loaded, ~1.15 GB after serving a request, and about 20 seconds of cold start before the API answers.

That means it requires Railway's Hobby plan or above. On the Trial (1 GB) and Free (0.5 GB) plans the container is OOM-killed during model load with exit status 137 and never serves traffic. If you are on one of those plans, deploy Kokoro TTS Lite instead — same OpenAI-compatible /v1/audio/speech, ONNX runtime, ~375 MB resident, runs on the Free plan.

A healthcheck on /health is configured, so Railway waits for the model to finish loading before routing traffic to a new deploy.

About Hosting Kokoro-FastAPI

Deploying Kokoro-FastAPI on Railway gives you an OpenAI-compatible text-to-speech API. The service supports multiple output formats (MP3, WAV, Opus, FLAC, M4A, PCM), streaming audio with configurable chunk sizes, and multi-language synthesis including English, Japanese, and Chinese. Advanced features include weighted voice combinations, word-level timestamped captions, and natural boundary detection for automatic sentence-based splitting. A built-in web UI and API documentation are included.

Common Use Cases

  • Drop-in replacement for OpenAI's text-to-speech API
  • Generating audio content in multiple languages
  • Creating custom voices by combining existing voice profiles
  • Producing captioned audio with word-level timestamps
  • Streaming audio generation for real-time applications

Dependencies for Kokoro-FastAPI Hosting

  • Docker container runtime
  • Kokoro-82M model (Apache 2.0 licensed)

Deployment Dependencies

Implementation Details

OpenAI-compatible client usage:

from openai import OpenAI

client = OpenAI(
    base_url="https://your-app.up.railway.app/v1",
    api_key="your-api-key"
)

response = client.audio.speech.create(
    model="kokoro",
    voice="af_bella",
    input="Hello world!"
)
response.stream_to_file("output.mp3")

Voice combinations with weighted ratios:

response = client.audio.speech.create(
    model="kokoro",
    voice="af_bella(2)+af_sky(1)",  # 67% bella, 33% sky
    input="Hello world!"
)

API Endpoints:

EndpointPurpose
POST /v1/audio/speechOpenAI-compatible speech synthesis
GET /v1/audio/voicesList available voices
POST /v1/audio/voices/combineCreate weighted voice combinations
POST /dev/captioned_speechGenerate audio with timestamps

Web Interfaces:

  • API Documentation: /docs
  • Web UI: /web

Why Deploy Kokoro-FastAPI on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying Kokoro-FastAPI on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
Chat Chat
Chat Chat, your own unified chat and search to AI platform.

okisdev
113
View Template
stella
Self-host stella with web, API, Postgres, Redis, and object storage.

Jan Kubica
1
View Template
Hermes Agent | OpenClaw Alternative with Dashboard
Self-Hosted Hermes AI Agent for Telegram, Discord & Slack

codestorm
56