Skip to content

Mistakenly treat no credits remaining error as "recoverable" error #7805

Closed

Description

@moz164164

Bug Description

OpenAI Realtime API returned an error: RealtimeError(message='You have no credits remaining. Add credits to continue using the API at https://platform.openai.com/settings/organization/billing/.', type='insufficient_quota', code='credit_balance_exhausted', event_id=None, param=None) is currently treated as "recoverable" error in livekit agent. When this error happen, realtime model fallback does not happen immediately. Instead, it just try to reconnect to the same provider until all retries exhausted (max_retry in APIConnectOptions). However, the session reconnection for the same provider is always successful in 1st retry attempt under this error and the count of retry is alway renewed to 0 after that. If this error keep happening again and again, the dead loop below will happen:

"OpenAI Realtime API returned an error: RealtimeError(message='You have no credits remaining..." -> session reconnection successful in 1st retry attempt -> count of retry is renewed to 0 -> "OpenAI Realtime API returned an error: RealtimeError(message='You have no credits remaining..." -> session reconnection successful in 1st retry attempt -> count of retry is renewed to 0 -> ....

Therefore, realtime model fallback will never happen and thus we cannot solve this error by switching to another realtime model provider automatically.

Also, this error is not something can be fixed immediately by retry.

Due to these 2 reason, I think it is not right to treat this error as "recoverable" error in livekit agent

Expected Behavior

Treat "OpenAI Realtime API returned an error: RealtimeError(message='You have no credits remaining. Add credits to continue using the API at https://platform.openai.com/settings/organization/billing/.', type='insufficient_quota', code='credit_balance_exhausted', event_id=None, param=None)" and those similar errors from other model providers as "unrecoverable" errors so that model fallback can be implemented immediately.

Reproduction Steps

1.   Use RealtimeModelFallbackAdapter with primary model "openai.realtime.RealtimeModel(
                    model="gpt-realtime",
                    voice="marin",
                    turn_detection=ServerVad( 
                        type="server_vad"
                        prefix_padding_ms=300,
                        silence_duration_ms=500,
                        threshold=0.5,
                        create_response=False,
                        interrupt_response=False,
                    ),
                    temperature=0.6,
                    input_audio_noise_reduction=NOT_GIVEN
                    ),
                    input_audio_transcription=AudioTranscription(language=lang, model="whisper-1"),
                    max_session_duration=55 * 60,  
                )" and set secondary model as its equivalent version provided by Azure
3. Keep simulate `RealtimeError(message='You have no credits remaining. Add credits to continue using the API at https://platform.openai.com/settings/organization/billing/.', type='insufficient_quota', code='credit_balance_exhausted', event_id=None, param=None)`

4. Check model fallback happen or not

Operating System

MacOS, linus

Models Used

gpt-realtime

Package Versions

livekit~=1.1,                                                       
livekit-agents[azure,openai,turn-detector,silero,elevenlabs]==1.8.2,
livekit-api~=1.1",
livekit-plugins-noise-cancellation~=0.2.0

Session/Room/Call IDs

No response

Proposed Solution

Treat OpenAI Realtime API returned an error: RealtimeError(message='You have no credits remaining. Add credits to continue using the API at https://platform.openai.com/settings/organization/billing/.', type='insufficient_quota', code='credit_balance_exhausted', event_id=None, param=None) and those similar errors from other model providers as "unrecoverable"

Additional Context

No response

Screenshots and Recordings

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions