├── deno.json ├── main.ts ├── README.MD └── README_EN.MD /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "dev": "deno run --watch main.ts" 4 | }, 5 | "imports": { 6 | "@std/assert": "jsr:@std/assert@1" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | async function handleRequest(request: Request): Promise { 2 | 3 | const url = new URL(request.url); 4 | const pathname = url.pathname; 5 | 6 | if (pathname === '/' || pathname === '/index.html') { 7 | return new Response('Proxy is Running!Details:https://github.com/tech-shrimp/deno-api-proxy', { 8 | status: 200, 9 | headers: { 'Content-Type': 'text/html' } 10 | }); 11 | } 12 | 13 | const targetUrl = `https://${pathname}`; 14 | 15 | try { 16 | const headers = new Headers(); 17 | const allowedHeaders = ['accept', 'content-type', 'authorization']; 18 | for (const [key, value] of request.headers.entries()) { 19 | if (allowedHeaders.includes(key.toLowerCase())) { 20 | headers.set(key, value); 21 | } 22 | } 23 | 24 | const response = await fetch(targetUrl, { 25 | method: request.method, 26 | headers: headers, 27 | body: request.body 28 | }); 29 | 30 | const responseHeaders = new Headers(response.headers); 31 | responseHeaders.set('Referrer-Policy', 'no-referrer'); 32 | 33 | return new Response(response.body, { 34 | status: response.status, 35 | headers: responseHeaders 36 | }); 37 | 38 | } catch (error) { 39 | console.error('Failed to fetch:', error); 40 | return new Response('Internal Server Error', { status: 500 }); 41 | } 42 | }; 43 | 44 | Deno.serve(handleRequest); -------------------------------------------------------------------------------- /README.MD: -------------------------------------------------------------------------------- 1 | # Deno API代理 2 | # Deno API Proxy 3 | 4 | # [English Version](README_EN.MD) 5 | 6 | ### 作者:技术爬爬虾 7 | B站,YouTube,抖音,公众号 全网同名。转载请注明作者。 8 | 9 | ## 项目简介 10 | 使用Deno将Open AI, Claude, Groq等API代理到国内,打破地域限制。 11 | 12 | ## Deno部署(推荐) 13 | 14 | 1. 登录/注册 [https://dash.deno.com/account/projects](https://dash.deno.com/account/projects) 15 | 2. 点击右上角的New Playground 16 | 3. 把main.ts里面所有代码复制进去 17 | 4. 点击 Save & Deploy 18 | 5. 查看部署后的服务的域名(长这样:xxx.deno.dev) 19 | 6. 将域名,需要代理的服务名字,API Key填入下方命令中 20 | 21 | 代理 OepnAI 22 | ``` 23 | curl --location 'https://YOUR-DOMAIN/api.openai.com/v1/chat/completions' \ 24 | --header 'Authorization: Bearer YOUR-API-KEY' \ 25 | --header 'Content-Type: application/json' \ 26 | 27 | --data '{ 28 | "messages": [ 29 | { 30 | "role": "system", 31 | "content": "You are a test assistant." 32 | }, 33 | { 34 | "role": "user", 35 | "content": "Testing. Just say hi and nothing else." 36 | } 37 | ], 38 | "model": "gemini-2.0-flash-exp" 39 | }' 40 | ``` 41 | 42 | 代理Groq 43 | ``` 44 | curl --location 'https://YOUR-DOMAIN/api.groq.com/v1/chat/completions' \ 45 | --header 'Authorization: Bearer YOUR-API-KEY' \ 46 | --header 'Content-Type: application/json' \ 47 | 48 | --data '{ 49 | "messages": [ 50 | { 51 | "role": "system", 52 | "content": "You are a test assistant." 53 | }, 54 | { 55 | "role": "user", 56 | "content": "Testing. Just say hi and nothing else." 57 | } 58 | ], 59 | "model": "gemini-2.0-flash-exp" 60 | }' 61 | ``` -------------------------------------------------------------------------------- /README_EN.MD: -------------------------------------------------------------------------------- 1 | # Deno API Proxy 2 | 3 | # [中文版本](README.MD) 4 | 5 | ### Author: Tech PaPaXia 6 | Find me on Bilibili, YouTube, TikTok, and WeChat Official Account under the same name. Please credit the author when sharing. 7 | 8 | ## Project Overview 9 | Use Deno to proxy Open AI, Claude, Groq and other APIs to mainland China, breaking geographical restrictions. 10 | 11 | ## Deno Deployment (Recommended) 12 | 13 | 1. Login/Register at [https://dash.deno.com/account/projects](https://dash.deno.com/account/projects) 14 | 2. Click "New Playground" in the top right corner 15 | 3. Copy all code from main.ts into the playground 16 | 4. Click "Save & Deploy" 17 | 5. Check the deployed service domain name (looks like: xxx.deno.dev) 18 | 6. Fill in your domain name, service name to proxy, and API Key in the commands below 19 | 20 | Proxy OpenAI 21 | ``` 22 | curl --location 'https://YOUR-DOMAIN/api.openai.com/v1/chat/completions' \ 23 | --header 'Authorization: Bearer YOUR-API-KEY' \ 24 | --header 'Content-Type: application/json' \ 25 | 26 | --data '{ 27 | "messages": [ 28 | { 29 | "role": "system", 30 | "content": "You are a test assistant." 31 | }, 32 | { 33 | "role": "user", 34 | "content": "Testing. Just say hi and nothing else." 35 | } 36 | ], 37 | "model": "gemini-2.0-flash-exp" 38 | }' 39 | ``` 40 | 41 | Proxy Groq 42 | ``` 43 | curl --location 'https://YOUR-DOMAIN/api.groq.com/v1/chat/completions' \ 44 | --header 'Authorization: Bearer YOUR-API-KEY' \ 45 | --header 'Content-Type: application/json' \ 46 | 47 | --data '{ 48 | "messages": [ 49 | { 50 | "role": "system", 51 | "content": "You are a test assistant." 52 | }, 53 | { 54 | "role": "user", 55 | "content": "Testing. Just say hi and nothing else." 56 | } 57 | ], 58 | "model": "gemini-2.0-flash-exp" 59 | }' 60 | ``` --------------------------------------------------------------------------------