Gemini API proxy on Vercel Edge is a proxy service designed to address issues of slow or inaccessible access to the Gemini API in certain regions.
Due to network conditions and geographical locations, access to the Gemini API can be slow or even impossible in some regions. To resolve this issue, we have created the Vercel Gemini Proxy, which allows users in these regions to access the Gemini API more quickly and reliably.
- This service must have its own domain name. Without a domain name, requests cannot be sent. Also, please try to set your DNS resolution in a region where Gemini allows access for successful connectivity.
- The project requires a
Gemini API Token
. Please set up and use your own token, and refrain from using tokens from others to prevent unauthorized use of the service. - If the
role
of the last or the first message in the message context is notuser
, the errorPlease ensure that multiturn requests ends with a user role or a function response.
may occur. Therefore, if therole
of the first message is notuser
, the service will automatically delete the first (ie. the first) message. If therole
of the last message is not user, an error will be reported and the message will not be sent to Gemini. - Only when the parameters meet all the conditions of
body
,key
andMethod
, can a normal request be made, otherwise a401
error will be returned. - Since Vercel may interrupt data, the service will first return a
200
status, wait for Gemini's reply, and return it to the user in the form of a stream. - You can check the log situation through the Vercel console Log.
$ curl "http://$YOU_SERVER_HOST:$PORT/api/v1beta/models/gemini-pro:streamGenerateContent?key=$GEMINI_API_TOKEN" \
-H "Content-Type: application/json" \
-H 'cache-control: no-cache' \
--data-raw '{"contents":[{"role":"user","parts":[{"text":"Hello Gemini"}]}]}'
--compressed