-
[issue-2202] [BE] [SDK] feat: Support OpenAI TTS models tracking (audio.speech) (#5010)
发布于
2026-02-23 14:12:46 +00:00 - feat(sdk): add TTS create decorator and audio patching
- Create audio/ module with TTSCreateTrackDecorator and
TTSStreamingResponseCreateTrackDecorator - Patch audio.speech.create and
audio.speech.with_streaming_response.create in opik_tracker.py - Track input parameters, character-based usage, model and provider
- Follow existing patterns from videos integration
- feat(backend): add audio_speech cost calculation
- Add inputCostPerCharacter field to ModelCostData
- Add audioInputCharacterPrice field to ModelPrice
- Add audioSpeechCost calculator to SpanCostCalculator
- Wire AUDIO_SPEECH mode in CostService.resolveCalculator()
- Cost = inputCostPerCharacter * input_characters from usage
- test: add unit tests for TTS integration and audio speech cost
Python SDK tests:
- test_openai_audio_speech_create__happyflow
- test_openai_audio_speech_with_streaming_response__happyflow
- test_openai_audio_speech_create__tts_1_hd (model name tracking)
- test_openai_audio_speech_create__with_optional_params
- test_openai_audio_speech_create__character_count_usage
Backend tests:
- audioSpeechCost calculator tests (zero price, zero chars, validation)
- audioSpeechCost for tts-1 and tts-1-hd pricing
- CostService integration tests for tts-1 and tts-1-hd
- Updated existing video tests for new ModelPrice constructor
- fix: address PR review - parameterize tests and remove unused imports
Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- fix: align TTS usage keys with OpikUsage pipeline and fix linting
Add completion_tokens:0 to TTS usage dicts so they correctly pass
through the OpenAI completions usage pipeline instead of falling
through to unknown provider format. Update test expectations to
match the actual backend-compatible usage format (original_usage.*
prefixed keys). Update backend audioSpeechCost to read
original_usage.input_characters with fallback for backward compat.
Fix ruff formatting issues.Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com
- Fix TTS streaming
Co-authored-by: Claude Opus 4.6 noreply@anthropic.com
Co-authored-by: Andres Cruz andresc@comet.com
Co-authored-by: Petro Tiurin 2856640+petrotiurin@users.noreply.github.com下载附件