Skip to content

lopins/vercel-api-proxy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中文 | English

Vercel API Proxy

Vercel API Proxy: Multi-API proxy gateway based on vercel routes

Support

  • openai
  • gemini
  • groq
  • claude
  • cohere
  • ...

How to deploy

Vercel CLI

Installing Vercel CLI

To download and install Vercel CLI, run the following command:

pnpm i -g vercel

Login Vercel

vercel login

Publish

Publish to Vercel

vercel --prod -y

WebSite

How to use

Configure proxy address

# openai
https://your.proxyapi.domian/openai/

# gemini
https://your.proxyapi.domian/gemini/

# groq
https://your.proxyapi.domian/groq/

# claude
https://your.proxyapi.domian/claude/

# cohere
https://your.proxyapi.domian/cohere/

API Usage

import random
import re

from openai import OpenAI

ApiKey = "sk-Qa7GFtgCspCVfVGqKhm43QFmEB1FxsFvkXNysVycCuwDv2rz"
BaseUrl = "https://your.proxyapi.domian/openai/v1"
models = [
    "gpt-3.5-turbo",
    "gpt-4o-mini"
]

def gentext():
    client = OpenAI(api_key=ApiKey, base_url=BaseUrl)
    model = random.choice(models)
    try:
        completion = client.chat.completions.create(
            model=model,
            messages=[
                {
                    "role": "system",
                    "content": "You are a smart and creative novelist."
                },
                {
                    "role": "user",
                    "content": "As the king of fairy tales, please write a short fairy tale, the theme of the story is to always maintain a kind heart, to stimulate children's interest and imagination in learning, and to help children better understand and accept the truth and values contained in the story. Only the story content is output, and the title and others are not required."
                }
            ],
            top_p=0.7,
            temperature=0.7
        )
        text = completion.choices[0].message.content
        print(f"{model}{re.sub(r'\n+', '', text)}")
    except Exception as e:
        print(f"{model}{str(e)}\n")

Vercel Region List

https://vercel.com/docs/edge-network/regions#region-list

Packages

No packages published

Languages

  • HTML 77.9%
  • JavaScript 22.1%