Skip to content

Fix Google Gemini OpenAI-compatible API integration #391

Open
@bhouston

Description

@bhouston

Issue Summary

After investigating issue #390 regarding the Google Gemini API integration with mycoder, I've identified potential causes for the error.

Findings

  1. The current implementation in mycoder supports using the OpenAI provider with alternative APIs through the baseUrl configuration, as evidenced by the xai provider which uses the OpenAIProvider.

  2. The error in issue Not Working with Google Gemini API #390 occurs when trying to use Google's Gemini API with the OpenAI-compatible endpoint:

export default {
    provider: 'openai',
    model: 'gemini-2.5-pro-exp-03-25',
    baseUrl: 'https://generativelanguage.googleapis.com/v1beta/openai',
    logLevel: 'verbose',
    githubMode: false,
    headless: true
};
  1. The error message indicates a 400 status code (bad request) with no response body:
Error: Error calling OpenAI API: 400 status code (no body)

Potential Causes

  1. Authentication Issues: The code is likely not passing the API key in the correct format for Google's API. Google Gemini API might require an API key to be passed differently than OpenAI.

  2. Request Format Incompatibility: While Google advertises OpenAI compatibility, there might be subtle differences in the request format or required parameters.

  3. Endpoint URL Structure: The endpoint URL might need to be structured differently, possibly requiring additional path components or query parameters.

Recommended Next Steps

  1. Review Google's Gemini API documentation for their OpenAI-compatible endpoint to understand authentication requirements.

  2. Add explicit support for Google Gemini in the provider registry, similar to how xai is implemented but with any Gemini-specific adjustments.

  3. Consider adding debug logging to capture the exact request being sent and any response headers to better diagnose the issue.

  4. Create a test case specifically for the Google Gemini OpenAI-compatible API to verify the integration.

I'll continue investigating the specific requirements for Google's OpenAI-compatible API and provide further updates.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions