DavidKk / Vercel-Gemini-Proxy

Gemini API proxy on Vercel Edge.

Home Page:https://github.com/DavidKk/vercel-gemini-proxy

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

https://github.com/DavidKk/vercel-gemini-proxy

License:MIT License


Languages

Language:TypeScript 74.9%Language:JavaScript 25.1%