# OpenAI and ElevenLabs speech compatibility

KaziVoice supports the existing OpenAI and ElevenLabs **speech SDK request and
response contracts**, backed by KaziVoice regional voices and OmniVoice clones.
You do not need a new client library for the supported calls. Change the API
key and base URL. Changing a key alone cannot redirect a client whose URL still
points to OpenAI or ElevenLabs.

## Connect

| Client | Base URL | Authentication |
| --- | --- | --- |
| OpenAI SDK | `https://kazivoice.aibuilds.nyc.boxd.sh/v1` | `Authorization: Bearer <KaziVoice key>` |
| ElevenLabs SDK | `https://kazivoice.aibuilds.nyc.boxd.sh/elevenlabs` | `xi-api-key: <KaziVoice key>` |

Copy **Workspace API key** at `/studio#playground`. This is a capability credential
for the existing browser workspace: it gives access to the same saved voices
without requiring `X-Workspace-Key`. The key is created locally from that
workspace's random key, with the `sk-vllm-` prefix. Do not share it. Clearing the
browser's stored workspace key loses access unless you retained the credential.
There is no separate key revocation or account recovery system in this release.

Operator-configured `VOICELLM_API_KEYS` also work. When
`VOICELLM_API_KEY_ENABLED=true`, the supplied SDK key must be in that configured
list; generated workspace keys do not bypass server authentication. A configured
key without the workspace prefix gets a separate private API workspace. Browser
workspace keys are accepted on this demo when global API-key protection is off;
arbitrary placeholder strings and original-provider keys are rejected.

### OpenAI Python

```python
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["KAZIVOICE_API_KEY"],
    base_url="https://kazivoice.aibuilds.nyc.boxd.sh/v1",
)
with client.audio.speech.with_streaming_response.create(
    model="gpt-4o-mini-tts",
    voice="alloy",
    input="Welcome to KaziVoice.",
    response_format="mp3",
) as response:
    response.stream_to_file("speech.mp3")
```

### OpenAI JavaScript

```javascript
import OpenAI from "openai";
import { writeFile } from "node:fs/promises";

const client = new OpenAI({
  apiKey: process.env.KAZIVOICE_API_KEY,
  baseURL: "https://kazivoice.aibuilds.nyc.boxd.sh/v1",
});
const response = await client.audio.speech.create({
  model: "gpt-4o-mini-tts",
  voice: "alloy",
  input: "Welcome to KaziVoice.",
});
await writeFile("speech.mp3", Buffer.from(await response.arrayBuffer()));
```

### ElevenLabs Python

```python
import os
from elevenlabs.client import ElevenLabs

client = ElevenLabs(
    api_key=os.environ["KAZIVOICE_API_KEY"],
    base_url="https://kazivoice.aibuilds.nyc.boxd.sh/elevenlabs",
)
audio = client.text_to_speech.convert(
    voice_id="21m00Tcm4TlvDq8ikWAM",
    model_id="eleven_multilingual_v2",
    text="Welcome to KaziVoice.",
    output_format="mp3_44100_128",
)
with open("speech.mp3", "wb") as file:
    file.write(b"".join(audio))
```

The legacy voice ID in this example is explicitly mapped to KaziVoice's
American English voice (Aria). It does not reproduce the original provider speaker.

## Supported routes

| OpenAI | Behavior |
| --- | --- |
| `POST /v1/audio/speech` | `model`, `voice`, `input`, `response_format`, `speed`, `stream_format`; returns audio bytes |
| `GET /v1/models` | OpenAI list envelope with KaziVoice speech model aliases |
| `GET /v1/models/{id}` | OpenAI model object |

Formats: MP3, Opus in Ogg, AAC, FLAC, WAV, and raw signed 16-bit little-endian
mono PCM at 24 kHz. Speed supports 0.25–4.0 using pitch-preserving tempo changes.
`voice` accepts a preset name, a KaziVoice profile ID, or `{"id":"clone_..."}`.
`language_code` and `quality` are optional KaziVoice extensions, passed with the
SDK's `extra_body`. Saved clones support cross-language output.

| ElevenLabs (under the `/elevenlabs` base URL) | Behavior |
| --- | --- |
| `POST /v1/text-to-speech/{id}` | Binary audio, standard JSON speech body |
| `POST /v1/text-to-speech/{id}/stream` | Audio byte iterator |
| `POST /v1/text-to-speech/{id}/with-timestamps` | Audio plus explicitly estimated character timing |
| `POST /v1/text-to-speech/{id}/stream/with-timestamps` | NDJSON delivery with estimated character timing |
| `GET /v1/voices` | Voice catalog including the key's private saved voices |
| `GET /v2/voices` | Search, filters and pagination (`page_size`, `next_page_token`) |
| `GET /v1/voices/{id}` | Voice details |
| `DELETE /v1/voices/{id}` | Delete an owned clone and private reference |
| `POST /v1/voices/add` | One 3–10 second reference, with transcript/permission extensions |
| `GET /v1/models` | ElevenLabs model list |

ElevenLabs output presets match their codec, sample rate and bitrate: MP3 at
22.05/24/44.1 kHz, Opus at 48 kHz, PCM/WAV at 8–48 kHz, and 8 kHz μ-law/A-law
for telephone audio. `voice_settings.speed` works. Default stability 0.5,
similarity boost 0.75, style 0, speaker boost true, and clone strength 0 are
accepted for request compatibility; KaziVoice does not implement independent
ElevenLabs stability/similarity/style controls. Non-default values return errors.

Both interfaces also exist directly at the host's `/v1` and `/v2` paths. On
`/v1/models`, the `xi-api-key` header selects the ElevenLabs list shape; Bearer
selects the OpenAI list shape. The `/elevenlabs` namespace avoids ambiguity.

## Models, voice aliases and Africa

OpenAI aliases: `tts-1`, `tts-1-hd`, `gpt-4o-mini-tts`,
`gpt-4o-mini-tts-2025-12-15`. KaziVoice names: `voicellm-1`, `voicellm-1-hd`.
ElevenLabs aliases include `eleven_multilingual_v2`, `eleven_turbo_v2`,
`eleven_turbo_v2_5`, `eleven_flash_v2`, `eleven_flash_v2_5`, and `eleven_v3`.
These are routing aliases, not hosted copies of those providers' models. HD/v3
select 32-step quality for OmniVoice; other aliases use Fast mode by default.
They do not change an Edge voice's underlying model.

OpenAI built-in names `alloy`, `ash`, `ballad`, `coral`, `echo`, `fable`, `onyx`,
`nova`, `sage`, `shimmer`, `verse`, `marin`, and `cedar` map to KaziVoice English
presets from the US and UK. Each OpenAI name maps to a distinct voice.
Regional African English remains available using its explicit KaziVoice ID. List `/v1/compatibility` with your
key for exact mappings, supported features and limits. Use native KaziVoice IDs
for African languages: `omni_sw`, `omni_ha`, `omni_yo`, `omni_ig`, `omni_tw`,
`omni_af`, `omni_zu`, and `omni_xh`, plus existing local and regional profiles.
Ghanaian Twi uses `omni_tw`; generic English is not represented as Ghanaian-accented.

A provider-specific or custom voice ID cannot transfer the original speaker by
changing credentials. Configure an explicit mapping to an owned KaziVoice voice:

```env
VOICELLM_COMPATIBILITY_VOICE_ALIASES={"your-existing-provider-id":"omni_sw"}
```

Unknown models and unmapped voices return 404. Profiles and clones remain
subject to their own upstream model terms, including OmniVoice non-commercial
weights. This compatibility layer does not supply provider-owned voices.

## Saved clones in an SDK

Use the clone ID from the studio in the existing `voice` / `voice_id` field.
Your workspace API key sees that same private voice. Another key receives 404.
For ElevenLabs-compatible clone creation, the `labels` field carries the extra
information OmniVoice needs; no ASR model is downloaded implicitly:

```python
voice = client.voices.ivc.create(
    name="My voice",
    files=[open("reference.wav", "rb")],
    labels={
        "language": "en",
        "transcript": "The exact words in this recording.",
        "permission_confirmed": "true",
    },
)
```

This upload call needs those extra labels; it is not an unchanged ElevenLabs
clone-training request. Upload one clip with one speaker, and have permission
for the reference voice. See the OmniVoice guide for storage and deletion rules.

## Limits and compatibility boundaries

- Up to 4,096 characters for ordinary voice requests; OmniVoice/saved clone
  requests remain limited to 1,500. These checks return clear errors.
- Audio iterator/SSE support is **delivery after completed inference**. It does
  not lower time to first sound through incremental model synthesis. Existing
  SDK streaming/file-saving methods work with these completed audio chunks.
- Free-form OpenAI `instructions`, realtime WebSockets, transcription,
  pronunciation dictionaries, request stitching, custom random seeds,
  background isolation and zero-retention mode are not supported. Requests
  asking for unsupported processing are rejected rather than quietly ignored.
- Timestamp routes return `alignment_source: estimated` and
  `X-Timestamp-Method: estimated`; timing is not forced alignment.
- API errors use OpenAI's `error` envelope or ElevenLabs' `detail` envelope.
  Responses carry request IDs, `Cache-Control: no-store`, `X-KaziVoice-Voice`,
  `X-Speech-Language`, and `X-Audio-Cached`.
- Private repeats share the existing render cache. Changing credentials changes
  workspace ownership. A saved voice cannot be accessed through another key.

## Reference and validation

Contracts reviewed from the official OpenAI Speech API reference and ElevenLabs
Create speech, Stream speech, List voices and Create IVC voice documentation:

- https://developers.openai.com/api/reference/resources/audio/subresources/speech/methods/create
- https://elevenlabs.io/docs/api-reference/text-to-speech/convert
- https://elevenlabs.io/docs/api-reference/text-to-speech/stream
- https://elevenlabs.io/docs/api-reference/voices/search
- https://elevenlabs.io/docs/api-reference/voices/ivc/create

Automated checks cover binary formats, rates, speed/pitch behavior, error shapes,
authentication, pagination, private clone access and reference upload limits.
Official OpenAI Python 3.55.1, OpenAI JavaScript, and ElevenLabs Python 2.79.0
were exercised against
a local API fixture for generation, streaming/file saving, models, voices, and SDK clone upload/deletion.
Real engine generation is checked separately from those protocol fixture tests.
