Hi Gemini Developers,
I’m currently working with the Gemini OpenAI-compatible API and have encountered an issue specifically related to how error responses are structured, which impacts error handling in the OpenAI Node API Library (the official openai
npm package).
The core problem is that when an error occurs, the API returns a JSON response where the root element is an array. For example, I received the following error:
[Actual JSON error response sample]
[
{
"error": {
"code": 429,
"message": "Gemini 2.5 Pro Preview doesn't have a free quota tier. Please use Gemini 2.5 Pro Experimental (models/gemini-2.5-pro-exp-03-25) instead. For more information on this error, head to: https://ai.google.dev/gemini-api/docs/rate-limits.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.QuotaFailure",
"violations": [
{
"quotaMetric": "generativelanguage.googleapis.com/generate_content_free_tier_requests",
"quotaId": "GenerateRequestsPerDayPerProjectPerModel-FreeTier",
"quotaDimensions": {
"model": "gemini-2.5-pro-exp",
"location": "global"
}
},
{
"quotaMetric": "generativelanguage.googleapis.com/generate_content_free_tier_requests",
"quotaId": "GenerateRequestsPerMinutePerProjectPerModel-FreeTier",
"quotaDimensions": {
"model": "gemini-2.5-pro-exp",
"location": "global"
}
},
{
"quotaMetric": "generativelanguage.googleapis.com/generate_content_free_tier_input_token_count",
"quotaId": "GenerateContentInputTokensPerModelPerMinute-FreeTier",
"quotaDimensions": {
"location": "global",
"model": "gemini-2.5-pro-exp"
}
},
{
"quotaMetric": "generativelanguage.googleapis.com/generate_content_free_tier_input_token_count",
"quotaId": "GenerateContentInputTokensPerModelPerDay-FreeTier",
"quotaDimensions": {
"location": "global",
"model": "gemini-2.5-pro-exp"
}
}
]
},
{
"@type": "type.googleapis.com/google.rpc.Help",
"links": [
{
"description": "Learn more about Gemini API quotas",
"url": "https://ai.google.dev/gemini-api/docs/rate-limits"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.RetryInfo",
"retryDelay": "58s"
}
]
}
}
]
This array-at-the-root structure causes issues with the OpenAI Node API Library (openai
). Instead of surfacing the detailed error message from the Gemini API (like the “message” field in the sample above), the openai
library often interprets the response as having “no body.” This can lead to confusing and non-descriptive errors for the developer, such as “APIError: 429 status code (no body)” or similar, even if the actual error details are present within the array returned by Gemini (as shown in my example). The library struggles because it expects a JSON object at the root (e.g., { "error": { ... } }
) to correctly access and parse the actual error details, which become effectively inaccessible to the library due to the root array format.
Would it be possible for the Gemini API to return error responses as a root-level JSON object rather than an array? For instance, unwrapping the current array structure so the error object is the top-level element would significantly improve compatibility.
This change would allow libraries like the OpenAI Node API Library (openai
) to correctly parse the error details provided by Gemini, leading to a much clearer, more accurate, and predictable error handling experience for developers.
Thanks for your consideration and all the great work on Gemini!
Best regards,
msmhrt (Masami HIRATA)