Realtime (WebSocket)

NOXERY API

Realtime (WebSocket)

Short, direct guides for using the OpenAI-compatible API in your applications and agents.

WS /v1/realtime

Gerçek zamanlı sesli ve metinli sohbet için WebSocket köprüsü. İstemci Noxery API anahtarıyla bağlanır, oturum Azure Realtime'a aktarılır. Desteklenen modeller: gpt-realtime ve gpt-realtime-2-1 (ikisi de ses + metin).

Bağlantı

AlanGerekliAçıklama
modelEvetgpt-realtime-2-1 veya gpt-realtime.
AuthorizationEvet*Bearer nox-... header'ı. WebSocket istemcileri header gönderebiliyorsa bunu kullan.
api_keyHayırTarayıcı gibi header gönderemeyen istemciler için query parametresi. Anahtar loglara düşebileceği için üretimde önerilmez.
text
wss://api.noxery.net/v1/realtime?model=gpt-realtime-2-1
Authorization: Bearer nox-YOUR_KEY

Olay akışı

Bağlantı kurulunca istemci JSON olayları gönderir, sunucu JSON olayları döner. Tipik bir metin turu:

YönOlayAnlamı
→session.updateOturum ayarları: modalities (["text"] veya ["audio","text"]), instructions, voice, turn_detection.
→conversation.item.createKullanıcı mesajı ekle (input_text veya input_audio).
→response.createModel yanıtını başlat.
←response.output_text.delta / response.output_audio.deltaMetin veya ses (base64 PCM16) parçaları.
←response.doneTur bitti; response.usage içinde token sayıları. Kullanım burada hesaplanır.
←errorHata; error.message okunur, oturum kapanabilir.

Sesli turda mikrofon PCM16 parçalarını input_audio_buffer.append ile gönderip input_audio_buffer.commit + response.create çağır; turn_detection açıksa commit'i sunucu yapar.

Python örneği

python
import asyncio, json
from websockets.asyncio.client import connect

async def main():
    url = "wss://api.noxery.net/v1/realtime?model=gpt-realtime-2-1"
    async with connect(url, additional_headers={"Authorization": "Bearer nox-YOUR_KEY"}) as ws:
        await ws.send(json.dumps({"type": "session.update",
                                  "session": {"modalities": ["text"], "instructions": "Kısa cevap ver."}}))
        await ws.send(json.dumps({"type": "conversation.item.create",
                                  "item": {"type": "message", "role": "user",
                                           "content": [{"type": "input_text", "text": "Merhaba"}]}}))
        await ws.send(json.dumps({"type": "response.create"}))
        while True:
            ev = json.loads(await ws.recv())
            if ev.get("type") == "response.output_text.delta":
                print(ev["delta"], end="", flush=True)
            elif ev.get("type") == "response.done":
                print("\nusage:", ev["response"].get("usage"))
                break
            elif ev.get("type") == "error":
                raise SystemExit(ev["error"]["message"])

asyncio.run(main())

Notlar

Eşzamanlı oturum sayısı sunucu tarafında sınırlıdır (varsayılan 8); doluysa error olayı ve 1013 kapanışı gelir. Kullanım her response.done sonrası hesabına işlenir; /usage sayfasında /v1/realtime olarak görünür. Tarayıcıda anahtarı gizli tutmak istiyorsan önce kendi sunucundan kısa ömürlü bir anahtar üretip öyle bağlan.