Guides
OpenAI SDK compatibility
Speech recognition and synthesis use the same paths, fields and error shape as OpenAI’s audio API. Set the SDK’s base URL to https://api.ana-yurt.dev/v1 and pass your Ana-Yurt key as the API key.
#Setup
# pip install openai
import os
from openai import OpenAI
client = OpenAI(
api_key=os.environ["AY_API_KEY"],
base_url="https://api.ana-yurt.dev/v1",
)
# Speech synthesis
with client.audio.speech.with_streaming_response.create(
model="omnivoice-crh", # required by the SDK, ignored by the API
voice="sevil",
input="Hoş keldiñiz!",
response_format="mp3",
) as response:
response.stream_to_file("welcome.mp3")
# Speech recognition
with open("welcome.mp3", "rb") as audio:
transcript = client.audio.transcriptions.create(model="whisper-1", file=audio)
print(transcript.text) # Hoş keldiñiz!#What is supported
| SDK call | Ana-Yurt | Notes |
|---|---|---|
audio.transcriptions.create | Yes | All five response_format values. model, prompt, temperature are ignored. |
audio.speech.create | Yes | Voices servin and sevil; formats mp3, wav, opus. model and speed are ignored. |
audio.translations.create | No | Returns 404 not_found. |
| Chat, embeddings, images, files | No | Not offered. |
TypeScript and the voice field
Some SDK versions type voice as a list of OpenAI voice names. If the compiler rejects 'sevil', cast it (voice: 'sevil' as never) or upgrade the SDK.
Transliteration has no OpenAI equivalent; call POST /v1/translit with any HTTP client.
#Errors in the SDK
The SDKs raise their usual exceptions. code and type carry the values from the error table. The SDKs retry 429 and 5xx a couple of times by themselves; set max_retries (Python) or maxRetries (JavaScript) to change that.
import openai
try:
client.audio.speech.create(model="x", voice="alloy", input="Selâm")
except openai.BadRequestError as e:
print(e.status_code, e.code) # 400 invalid_request
except openai.RateLimitError as e:
retry_after = e.response.headers.get("Retry-After")
except openai.APIStatusError as e:
print(e.status_code, e.response.headers.get("X-Request-Id"))