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
- 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.
- After registering and logging in to your Google account, please visit Google AI Studio: https://aistudio.google.com/
- 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.
- After successful access, you will see an interface similar to the one below, which means you can start using Google AI Studio.
- 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.
Fill in the Information into pyVideoTrans's OpenAI API and Compatible AI Settings
- Open pyVideoTrans, find the configuration section of Menu -- Translation Settings -- OpenAI API and Compatible AI.
- Enter Gemini's OpenAI compatible API address
https://generativelanguage.googleapis.com/v1beta/openai/
into theAPI URL
input box. - Paste the Gemini API KEY copied in the previous step into the
SK
input box. - 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,
. - Then, select the Gemini model you want to use from the model list.
- After completing the above, click the "Save" button.
- 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.
- First, make sure the configuration has been saved.
- 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 behttp://127.0.0.1:10808
.
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 completehttp://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 ishttp://127.0.0.1:10808
.If the default port of your tool is
7890
, the proxy address ishttp://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.