@@ -6,6 +6,7 @@ import (
7 "net/http/httptest"
7 "net/http/httptest"
@@ -88,3 +89,78 @@ func TestOpenAIClientStreamChoices(t *testing.T) {
93+func TestOpenAIClient429InsufficientQuotaError(t *testing.T) {
94+ client := &openaiClient{
95+ providerOptions: providerClientOptions{
96+ modelType: config.SelectedModelTypeLarge,
98+ systemMessage: "test",
99+ config: config.ProviderConfig{
103+ model: func(config.SelectedModelType) catwalk.Model {
104+ return catwalk.Model{
112+ // Test insufficient_quota error should not retry
113+ apiErr := &openai.Error{
115+ Message: "You exceeded your current quota, please check your plan and billing details. For more information on this error, read the docs: https://platform.openai.com/docs/guides/error-codes/api-errors.",
116+ Type: "insufficient_quota",
117+ Code: "insufficient_quota",
120+ retry, _, err := client.shouldRetry(1, apiErr)
122+ t.Error("Expected shouldRetry to return false for insufficient_quota error, but got true")
125+ t.Error("Expected shouldRetry to return an error for insufficient_quota, but got nil")
127+ if err != nil && !strings.Contains(err.Error(), "quota") {
128+ t.Errorf("Expected error message to mention quota, got: %v", err)
132+func TestOpenAIClient429RateLimitError(t *testing.T) {
133+ client := &openaiClient{
134+ providerOptions: providerClientOptions{
135+ modelType: config.SelectedModelTypeLarge,
137+ systemMessage: "test",
138+ config: config.ProviderConfig{
142+ model: func(config.SelectedModelType) catwalk.Model {
143+ return catwalk.Model{
151+ // Test regular rate limit error should retry
152+ apiErr := &openai.Error{
154+ Message: "Rate limit reached for requests",
155+ Type: "rate_limit_exceeded",
156+ Code: "rate_limit_exceeded",
159+ retry, _, err := client.shouldRetry(1, apiErr)
161+ t.Error("Expected shouldRetry to return true for rate_limit_exceeded error, but got false")
164+ t.Errorf("Expected shouldRetry to return nil error for rate_limit_exceeded, but got: %v", err)