├── LICENSE ├── README.md ├── deno.json ├── deno.lock ├── package.json └── src └── deno_index.ts /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Grok 3 地球上最聪明的AI 2 | 3 | 使用 Deno 免费代理马斯克 Grok3,免登录,国内直连,不限地区/不限网络/不限设备,打开即用。 4 | 5 | 出道即巅峰,Grok3 是首个突破1400分的模型,并且在所有类别中排名第一。 6 | 7 | 大家好!今天要带你们解锁地表最强AI——Grok 3!马斯克亲封的 "最聪明AI" 8 | 9 | 10 | `#马斯克AI革命` `#Grok3性能屠榜` `#超越DeepSeekR1` `#20万GPU算力碾压` `#地表最强AI` 11 | 12 | 1. 算力碾压: 13 | - 20万块H100 GPU训练,算力是DeepSeek R1的50倍(DeepSeek R1仅用2048块H800 GPU)。 14 | - 训练耗时2亿GPU小时,是Grok 2的10倍,硬件规模全球第一。 15 | 2. 性能屠榜: 16 | - 数学能力:AIME'24测试96分(DeepSeek V3仅39分)。 17 | - 编程效率:LCB测试57分,15分钟生成《星际俄罗斯方块》完整代码。 18 | - 推理能力:Chatbot Arena ELO评分1400+,全球首个突破此分数的模型。 19 | 3. 独家功能碾压: 20 | - DeepSearch:实时联网搜索+多源验证(对比DeepSeek R1依赖中文自媒体,Grok 3抓取GitHub、arXiv等权威数据,例:分析特斯拉股价趋势)。 21 | - Think模式:思维链长度是DeepSeek R1的10倍,推理速度反而更快,复杂问题分步推理(如生成3D行星轨道代码)。 22 | - 多模态处理:同步解析文本+图像(例:分析医学CT报告) 23 | 24 | ## 分享 25 | 26 | - [Midjourney API](https://github.com/trueai-org/midjourney-proxy):市面上最强大,完全免费开源的免费绘图平台。 27 | - [MDrive](https://github.com/trueai-org/mdrive):阿里云盘官方 API 授权的自动同步和备份工具,支持挂载到本地磁盘。 28 | - [Gemini](https://github.com/trueai-org/gemini):使用 Deno 免费代理 Google Gemini,国内直连,不限地区/网络环境,打开即用。 29 | 30 | ## Deno 部署 31 | 32 | > Bilibili 视频教程: 33 | 34 | 1. 点击 [Fork](https://github.com/trueai-org/grok/fork) 本项目(万分感谢帮助点个 `Star`) 35 | 2. 登录/注册 X 账号 (用 Gmail 或 Outlook 邮箱登录 X 官网) 36 | 3. 点击创建 Deno 项目 https://dash.deno.com/new_project 37 | 4. 选择此项目,填写项目名字(分配 Deno 域名) 38 | 5. 部署 Entrypoint 填写 `src/deno_index.ts` 其他字段留空 39 | 6. 点击 **Deploy Project** 40 | 7. 部署成功后获得 Deno 域名,打开刚刚部署项目 -> `Settings` -> `Environment Variables` -> 添加 cookie 到环境变量,完成后就可以在任意地点/任意设备访问 Grok3 了。 41 | 42 | > 如果需要配置账号密码,则配置 Deno 环境变量 AUTH_USERNAME 和 AUTH_PASSWORD。 43 | 44 | ## Deno 调试 45 | 46 | Windows 安装 Deno: 47 | > irm https://deno.land/install.ps1 | iex 48 | 49 | Mac/Linux 安装 Deno: 50 | > curl -fsSL https://deno.land/install.sh | sh 51 | 52 | 启动项目: 53 | 54 | > cd grok 55 | 56 | > deno run --allow-env --allow-net --allow-read src/deno_index.ts 57 | 58 | ## 其他说明 59 | 60 | 1. 免费体验,Grork3 每日有频率限制(Grok2 不限次数) 61 | 1. 科学上网:连接美国/新加坡节点(推荐使用V2Ray协议加速) 62 | 2. 注册 X 账号:用 Gmail 或 Outlook 邮箱登录 X 官网 63 | 3. 访问入口:点击 x.com Grok 页面或 grok.com,无需订阅即可使用基础功能 64 | 4. 付费解锁全功能(Premium+订阅,申请虚拟卡等方式) 65 | -------------------------------------------------------------------------------- /deno.json: -------------------------------------------------------------------------------- 1 | { 2 | "tasks": { 3 | "start": "deno run --allow-env --allow-net --allow-read src/deno_index.ts" 4 | } 5 | } -------------------------------------------------------------------------------- /deno.lock: -------------------------------------------------------------------------------- 1 | { 2 | "version": "4", 3 | "remote": { 4 | "https://deno.land/std@0.202.0/async/delay.ts": "a6142eb44cdd856b645086af2b811b1fcce08ec06bb7d50969e6a872ee9b8659", 5 | "https://deno.land/std@0.202.0/http/server.ts": "1b2403b3c544c0624ad23e8ca4e05877e65380d9e0d75d04957432d65c3d5f41" 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "grok3", 3 | "version": "0.0.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "node src/deno_index.ts" 7 | }, 8 | "devDependencies": {} 9 | } 10 | -------------------------------------------------------------------------------- /src/deno_index.ts: -------------------------------------------------------------------------------- 1 | import { serve } from "https://deno.land/std@0.202.0/http/server.ts"; 2 | 3 | const TARGET_URL = "https://grok.com"; 4 | const ORIGIN_DOMAIN = "grok.com"; // 注意:此处应仅为域名,不含协议 5 | 6 | const AUTH_USERNAME = Deno.env.get("AUTH_USERNAME"); 7 | const AUTH_PASSWORD = Deno.env.get("AUTH_PASSWORD"); 8 | 9 | const COOKIE = Deno.env.get("cookie"); 10 | 11 | // 验证函数 12 | function isValidAuth(authHeader: string): boolean { 13 | try { 14 | const base64Credentials = authHeader.split(" ")[1]; 15 | const credentials = atob(base64Credentials); 16 | const [username, password] = credentials.split(":"); 17 | return username === AUTH_USERNAME && password === AUTH_PASSWORD; 18 | } catch { 19 | return false; 20 | } 21 | } 22 | async function handleWebSocket(req: Request): Promise { 23 | const { socket: clientWs, response } = Deno.upgradeWebSocket(req); 24 | 25 | const url = new URL(req.url); 26 | const targetUrl = `wss://grok.com${url.pathname}${url.search}`; 27 | 28 | console.log('Target URL:', targetUrl); 29 | 30 | const pendingMessages: string[] = []; 31 | const targetWs = new WebSocket(targetUrl); 32 | 33 | targetWs.onopen = () => { 34 | console.log('Connected to grok'); 35 | pendingMessages.forEach(msg => targetWs.send(msg)); 36 | pendingMessages.length = 0; 37 | }; 38 | 39 | clientWs.onmessage = (event) => { 40 | console.log('Client message received'); 41 | if (targetWs.readyState === WebSocket.OPEN) { 42 | targetWs.send(event.data); 43 | } else { 44 | pendingMessages.push(event.data); 45 | } 46 | }; 47 | 48 | targetWs.onmessage = (event) => { 49 | console.log('message received'); 50 | if (clientWs.readyState === WebSocket.OPEN) { 51 | clientWs.send(event.data); 52 | } 53 | }; 54 | 55 | clientWs.onclose = (event) => { 56 | console.log('Client connection closed'); 57 | if (targetWs.readyState === WebSocket.OPEN) { 58 | targetWs.close(1000, event.reason); 59 | } 60 | }; 61 | 62 | targetWs.onclose = (event) => { 63 | console.log('connection closed'); 64 | if (clientWs.readyState === WebSocket.OPEN) { 65 | clientWs.close(event.code, event.reason); 66 | } 67 | }; 68 | 69 | targetWs.onerror = (error) => { 70 | console.error('WebSocket error:', error); 71 | }; 72 | 73 | return response; 74 | } 75 | 76 | 77 | const handler = async (req: Request): Promise => { 78 | // Basic Auth 验证 79 | const authHeader = req.headers.get("Authorization"); 80 | if (AUTH_USERNAME && AUTH_PASSWORD && (!authHeader || !isValidAuth(authHeader))) { 81 | return new Response("Unauthorized", { 82 | status: 401, 83 | headers: { 84 | "WWW-Authenticate": 'Basic realm="Proxy Authentication Required"', 85 | }, 86 | }); 87 | } 88 | 89 | if (req.headers.get("Upgrade")?.toLowerCase() === "websocket") { 90 | return handleWebSocket(req); 91 | } 92 | 93 | const url = new URL(req.url); 94 | const targetUrl = new URL(url.pathname + url.search, TARGET_URL); 95 | 96 | // 构造代理请求 97 | const headers = new Headers(req.headers); 98 | headers.set("Host", targetUrl.host); 99 | headers.delete("Referer"); 100 | headers.delete("Cookie"); 101 | headers.delete("Authorization"); // 删除验证头,不转发到目标服务器 102 | headers.set("cookie", COOKIE || ''); 103 | 104 | try { 105 | const proxyResponse = await fetch(targetUrl.toString(), { 106 | method: req.method, 107 | headers, 108 | body: req.body, 109 | redirect: "manual", 110 | }); 111 | 112 | // 处理响应头 113 | const responseHeaders = new Headers(proxyResponse.headers); 114 | responseHeaders.delete("Content-Length"); // 移除固定长度头 115 | const location = responseHeaders.get("Location"); 116 | if (location) { 117 | responseHeaders.set("Location", location.replace(TARGET_URL, `https://${ORIGIN_DOMAIN}`)); 118 | } 119 | 120 | // 处理无响应体状态码 121 | if ([204, 205, 304].includes(proxyResponse.status)) { 122 | return new Response(null, { status: proxyResponse.status, headers: responseHeaders }); 123 | } 124 | 125 | // 创建流式转换器 126 | const transformStream = new TransformStream({ 127 | transform: async (chunk, controller) => { 128 | const contentType = responseHeaders.get("Content-Type") || ""; 129 | if (contentType.startsWith("text/") || contentType.includes("json")) { 130 | let text = new TextDecoder("utf-8", { stream: true }).decode(chunk); 131 | 132 | // if(contentType.includes("json")) 133 | // { 134 | // if(text.includes("streamingImageGenerationResponse")) 135 | // { 136 | // text = text.replaceAll('users/','https://assets.grok.com/users/'); 137 | // } 138 | // } 139 | 140 | controller.enqueue( 141 | new TextEncoder().encode(text.replaceAll(TARGET_URL, ORIGIN_DOMAIN)) 142 | ); 143 | } else { 144 | controller.enqueue(chunk); 145 | } 146 | } 147 | }); 148 | 149 | // 创建可读流 150 | const readableStream = proxyResponse.body?.pipeThrough(transformStream); 151 | 152 | return new Response(readableStream, { 153 | status: proxyResponse.status, 154 | headers: responseHeaders, 155 | }); 156 | } catch (error) { 157 | return new Response(`Proxy Error: ${error.message}`, { status: 500 }); 158 | } 159 | }; 160 | 161 | serve(handler, { port: 8000 }); 162 | --------------------------------------------------------------------------------