Skip to content

IamWills/Vercel-Gemini-Proxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

build.workflow License: MIT codecov

Vercel Gemini Proxy

中文 English

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.

Background

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.

Important Notes

  • 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 not user, the error Please ensure that multiturn requests ends with a user role or a function response. may occur. Therefore, if the role of the first message is not user, the service will automatically delete the first (ie. the first) message. If the role 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 and Method, can a normal request be made, otherwise a 401 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.

Deploy With Vercel

Deploy with Vercel

Usage

$ 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

About

Gemini API proxy on Vercel Edge.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 74.9%
  • JavaScript 25.1%