Skip to content

Gemini API Compatible with OpenAI Interface: How to Configure and Use for Free in Compatible Applications

The Gemini series of large models may be underestimated. Whether in terms of model capabilities, free quota, or service stability, it is in no way inferior to other mainstream models. In particular, its developer backend, Google AI Studio, is not only user-friendly and easy to operate, but also offers a very generous free usage quota. As a result, Gemini has become my primary large model.

Notably, Gemini is also compatible with the OpenAI API interface specification. This means you can seamlessly switch to Gemini in many applications that support the OpenAI API with simple configuration modifications. Many people may not be aware of this.

Below, I will use the pyVideoTrans tool as an example to demonstrate how to configure it to use the Gemini API.

Free Registration of a Google Account and Obtaining a Gemini API KEY

  1. First, you need a Google account. If you don't have one, you can register for free using a mobile phone number. The whole process is free, but please note that you need a "scientific internet access" environment to access related services.
  2. After registering and logging in to your Google account, please visit Google AI Studio: https://aistudio.google.com/
  3. Google AI Studio has access restrictions in some countries/regions. If you see the following prompt page, it means that the region where your current "ladder" node is located is restricted. Try switching to nodes in other countries/regions until you can access it normally. This interface indicates that the used ladder node is not allowed to access, please switch to another country node
  4. After successful access, you will see an interface similar to the one below, which means you can start using Google AI Studio. Seeing this interface indicates availability
  5. Next, we need to obtain the API Key. As shown in the figure below, click the Get API key button in the upper right corner of the page. If you have not created one before, the system may guide you to create a project first and then generate an API Key. Please follow the prompts. Click here to copy the API key. If the key does not exist, create it as instructed

Fill in the Information into pyVideoTrans's OpenAI API and Compatible AI Settings

  1. Open pyVideoTrans, find the configuration section of Menu -- Translation Settings -- OpenAI API and Compatible AI.
  2. Enter Gemini's OpenAI compatible API address https://generativelanguage.googleapis.com/v1beta/openai/ into the API URL input box.
  3. Paste the Gemini API KEY copied in the previous step into the SK input box.
  4. In the Fill in all available models text box below, enter the Gemini model names you want to use. You can find these model names from the Google AI Studio interface (e.g., gemini-2.5-flash-preview-04-17,gemini-2.5-pro-preview-05-06,gemini-2.0-flash). If you need to add multiple models, separate them with an English comma ,. Copy the name of the model you want to use as shown in the figure
  5. Then, select the Gemini model you want to use from the model list. Effect after filling in
  6. After completing the above, click the "Save" button.
  7. Test Connection: If you have set up a valid network proxy in the main interface of pyVideoTrans, or your computer has a configured global proxy (system proxy), you can click the "Test" button at this time. If the test passes without any errors, it means the configuration is successful, and the Gemini API can be used normally in pyVideoTrans.

What if a Network Connection Error Occurs?

If a network connection-related error message appears after clicking "Test", the problem is likely with the network proxy configuration.

  1. First, make sure the configuration has been saved.
  2. Then, check the "scientific internet access" tool you are using:
    • Is "Automatically configure system proxy" or "Global proxy" mode enabled? If not, try enabling it and test again.
    • Manually configure the proxy: If you do not want to or cannot enable the global proxy, you can find the local HTTP proxy address and port number provided by the "scientific internet access" tool. The format is usually http://IP address:port number. Fill this address completely into the "Network Proxy" text box in the main interface of pyVideoTrans. For example, the default local proxy address of some tools may be http://127.0.0.1:10808. The proxy address is generally in the form of http://127.0.0.1 followed by an English colon and port number

Most "scientific internet access" tools provide a local proxy IP address and port number. The IP address is usually 127.0.0.1 (representing the local machine), and you need to find the specific port number corresponding to the tool. Then fill in the complete http://127.0.0.1:port number into the network proxy settings of pyVideoTrans.

Here are some examples of common scientific tool port numbers:

  • If the default port of your tool is 10808, the proxy address is http://127.0.0.1:10808. Different scientific tools provide different default ports. The default port number of this tool is 10808

  • If the default port of your tool is 7890, the proxy address is http://127.0.0.1:7890. The default port of this tool is 7890, so you need to fill in http://127.0.0.1:7890

After correctly configuring the proxy, test the connection again, and you should be able to successfully use the Gemini API.