├── .vscode └── settings.json ├── README.md ├── code.md ├── main.ts ├── regions.ts └── render.ts /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "deno.enable": true, 3 | "deno.lint": true, 4 | "deno.unstable": false 5 | } 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # OpenAI/ChatGPT Proxy Via Deno 2 | 3 | ## Usage 4 | 5 | Using OpenAI/ChatGPT official npm package: 6 | 7 | ```diff 8 | import { Configuration } from "openai"; 9 | 10 | const configuration = new Configuration({ 11 | apiKey: process.env.OPENAI_API_KEY, 12 | + basePath: "https://linkai.deno.dev/v1", 13 | }); 14 | ``` 15 | 16 | Using OpenAI/ChatGPT official Python package: 17 | 18 | ```diff 19 | import openai 20 | 21 | openai.api_key = os.getenv("OPENAI_API_KEY") 22 | + openai.api_base = "https://linkai.deno.dev/v1" 23 | ``` 24 | 25 | ## Getting Started With Local Development 26 | 27 | ```bash 28 | deno run --allow-net --allow-read --allow-env --watch main.ts 29 | ``` 30 | 31 | ## Self-Hosting 32 | 33 | Use `DENO_REGION` to serve region-specific content in your Deno projects, which is useful for users in different parts of the world. Check out the documentation at https://deno.com/deploy/docs/projects#preset-variables. 34 | 35 | > Check the list of supported countries at https://platform.openai.com/docs/supported-countries/supported-countries-and-territories and select those regions for your project to ensure your users can access OpenAI features. 36 | 37 | Click this [link][1] to quickly deploy to Deno Deploy with one click. 38 | 39 | [1]: https://dash.deno.com/new?url=https://raw.githubusercontent.com/gptea-ai/link-to-openai/main/main.ts -------------------------------------------------------------------------------- /code.md: -------------------------------------------------------------------------------- 1 | ```typescript 2 | // typescript 3 | import { Configuration } from "openai"; 4 | 5 | const configuration = new Configuration({ 6 | apiKey: process.env.OPENAI_API_KEY, 7 | basePath: "https://linkai.deno.dev/v1", 8 | }); 9 | 10 | 11 | // python 12 | import openai 13 | 14 | openai.api_key = os.getenv("OPENAI_API_KEY") 15 | openai.api_base = "https://linkai.deno.dev/v1" 16 | 17 | ``` -------------------------------------------------------------------------------- /main.ts: -------------------------------------------------------------------------------- 1 | import { serve } from "https://deno.land/std@0.140.0/http/server.ts"; 2 | import { buildPortal } from "./render.ts"; 3 | 4 | const OPEN_AI_API_HOST = "api.openai.com"; 5 | 6 | async function handler(request: Request): Promise { 7 | const url = new URL(request.url); 8 | 9 | if (url.pathname === "/") { 10 | return new Response(await buildPortal(), { 11 | headers: { 12 | "content-type": "text/html;charset=UTF-8", 13 | }, 14 | }); 15 | } 16 | 17 | url.host = OPEN_AI_API_HOST; 18 | return await fetch(url, request); 19 | } 20 | 21 | serve(handler); -------------------------------------------------------------------------------- /regions.ts: -------------------------------------------------------------------------------- 1 | /* 2 | This script will export a default object containing 3 | a list of active Deno Deploy regions, sourced from 4 | https://deno.com/deploy/docs/regions and updated 5 | manually. Each region has a geographic name and a 6 | system name, the latter returned from the 7 | DENO_REGION environment variable on Deno Deploy. 8 | */ 9 | 10 | interface RegionObject { 11 | [key: string]: string; 12 | } 13 | 14 | export default { 15 | "asia-east1": "Taiwan", 16 | "asia-east2": "Hong Kong", 17 | "asia-northeast1": "Tokyo", 18 | "asia-northeast2": "Osaka", 19 | "asia-northeast3": "Seoul", 20 | "asia-south1": "Mumbai", 21 | "asia-south2": "Delhi", 22 | "asia-southeast1": "Singapore", 23 | "asia-southeast2": "Jakarta", 24 | "australia-southeast1": "Sydney", 25 | "australia-southeast2": "Melbourne", 26 | "europe-central2": "Warsaw", 27 | "europe-north1": "Finland", 28 | "europe-west1": "Belgium", 29 | "europe-west2": "London", 30 | "europe-west3": "Frankfurt", 31 | "europe-west4": "Netherlands", 32 | "europe-west6": "Zurich", 33 | "europe-west8": "Milan", 34 | "europe-west9": "Paris", 35 | "me-west1": "Tel Aviv", 36 | "europe-southwest-1": "Madrid", 37 | "northamerica-northeast1": "Montréal", 38 | "northamerica-northeast2": "Toronto", 39 | "southamerica-east1": "São Paulo", 40 | "southamerica-west1": "Chile", 41 | "us-central1": "Iowa", 42 | "us-east1": "South Carolina", 43 | "us-east4": "North Virginia", 44 | "us-east5": "Ohio", 45 | "us-south1": "Texas", 46 | "us-west1": "Oregon", 47 | "us-west2": "California", 48 | "us-west3": "Utah", 49 | "us-west4": "Nevada", 50 | } as RegionObject; -------------------------------------------------------------------------------- /render.ts: -------------------------------------------------------------------------------- 1 | import { CSS, render } from "https://deno.land/x/gfm/mod.ts"; 2 | import "https://esm.sh/prismjs@1.29.0/components/prism-typescript?no-check"; 3 | 4 | import regions from "./regions.ts"; 5 | 6 | 7 | export async function buildPortal() { 8 | const regionCode = Deno.env.get("DENO_REGION") || "localhost"; 9 | const regionText = regions[regionCode] ? regions[regionCode] : regionCode; 10 | const CODE = render(await Deno.readTextFile("./code.md")); 11 | const html = ` 12 | 13 | 14 | 15 | 16 | 17 | 20 | 21 | 22 | 23 |
24 |
25 |
26 |
27 |
28 |
29 | 34 |

OpenAI Proxy

35 |

Unrestricted Access to OpenAI/ChatGPT - Your Key to Limitless Creativity!

36 | 40 |
41 |
42 |
43 |
44 | 45 |
46 |
47 | 48 |
49 |
50 |
51 |
52 |
53 |
Code Examples
54 |
55 |
56 |
57 | ${CODE} 58 |
59 |
60 |
61 | 62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 | 71 | 72 | `; 73 | 74 | return html; 75 | } --------------------------------------------------------------------------------