[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-72131":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":20,"compositeScore":21,"rankGlobal":10,"rankLanguage":10,"license":22,"archived":23,"fork":23,"defaultBranch":24,"hasWiki":25,"hasPages":23,"topics":26,"createdAt":10,"pushedAt":10,"updatedAt":31,"readmeContent":32,"aiSummary":33,"trendingCount":16,"starSnapshotCount":16,"syncStatus":34,"lastSyncTime":35,"discoverSource":36},72131,"grok2api","chenyme\u002Fgrok2api","chenyme","Grok2API 是一个基于 FastAPI 构建的 Grok 网关，支持将 Grok Web 能力以 OpenAI 兼容 API 的方式转换。","https:\u002F\u002Fgrok2api-omega.vercel.app\u002F",null,"Python",5196,1810,13,30,0,64,143,396,192,40.77,"MIT License",false,"main",true,[27,28,29,30],"grok","grok-4-20","grok-4-3","grok-imagine","2026-06-12 02:02:59","\u003Cimg alt=\"Grok2API\" src=\"https:\u002F\u002Fgithub.com\u002Fuser-attachments\u002Fassets\u002F037a0a6e-7986-41cc-b4af-04df612ee886\" \u002F>\n\n[![Python](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fpython-3.13%2B-3776AB?logo=python&logoColor=white)](https:\u002F\u002Fwww.python.org\u002F)\n[![FastAPI](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FFastAPI-0.119%2B-009688?logo=fastapi&logoColor=white)](https:\u002F\u002Ffastapi.tiangolo.com\u002F)\n[![Version](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fversion-2.0.4.rc2-111827)](pyproject.toml)\n[![License](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Flicense-MIT-16a34a)](LICENSE)\n[![English](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FEnglish-2563EB?logo=bookstack&logoColor=white)](docs\u002FREADME.en.md)\n[![DeepWiki](https:\u002F\u002Fdeepwiki.com\u002Fbadge.svg)](https:\u002F\u002Fdeepwiki.com\u002Fchenyme\u002Fgrok2api)\n[![项目文档](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002F项目文档-0F766E?logo=readthedocs&logoColor=white)](https:\u002F\u002Fblog.cheny.me\u002Fblog\u002Fposts\u002Fgrok2api)\n\n\n> [!NOTE]\n> 本项目仅供学习与研究交流。请务必遵循 Grok 的使用条款及当地法律法规，不得用于非法用途！二开与 PR 请保留原作者与前端标识。\n\n\u003Cbr>\n\nGrok2API 是一个基于 **FastAPI** 构建的 Grok 网关，支持将 Grok Web 能力以 OpenAI 兼容 API 的方式转换。核心特性：\n- OpenAI 兼容接口：`\u002Fv1\u002Fmodels`、`\u002Fv1\u002Fchat\u002Fcompletions`、`\u002Fv1\u002Fresponses`、`\u002Fv1\u002Fimages\u002Fgenerations`、`\u002Fv1\u002Fimages\u002Fedits`、`\u002Fv1\u002Fvideos`、`\u002Fv1\u002Fvideos\u002F{video_id}`、`\u002Fv1\u002Fvideos\u002F{video_id}\u002Fcontent`\n- Anthropic 兼容接口：`\u002Fv1\u002Fmessages`\n- 支持流式与非流式对话、显式思考输出、函数工具结构透传，以及统一的 token \u002F usage 统计\n- 支持多账号池、层级选号、失败反馈、额度同步与自动维护\n- 支持本地缓存图片、视频与本地代理链接返回\n- 支持文生图、图像编辑、文生视频、图生视频\n- 内置 Admin 后台管理、Web Chat、Masonry 生图、ChatKit 语音页面\n\n\u003Cbr>\n\n## 服务架构\n\n```mermaid\nflowchart LR\n    Client[\"Clients\\nOpenAI SDK \u002F curl \u002F Browser\"] --> API[\"FastAPI App\"]\n\n    subgraph Products[\"Products\"]\n        direction TB\n        OpenAI[\"OpenAI APIs\\n\u002Fv1\u002F*\"]\n        Anthropic[\"Anthropic APIs\\n\u002Fv1\u002Fmessages\"]\n        Web[\"Web Products\\n\u002Fadmin \u002Fwebui\u002F*\"]\n    end\n\n    subgraph Control[\"Control\"]\n        direction TB\n        Models[\"Model Registry\"]\n        Accounts[\"Account Services\"]\n        Proxies[\"Proxy Services\"]\n    end\n\n    subgraph Dataplane[\"Dataplane\"]\n        direction TB\n        Reverse[\"Reverse Protocol + Transport\"]\n        AccountDP[\"AccountDirectory\"]\n        ProxyDP[\"Proxy Runtime\"]\n    end\n\n    subgraph Platform[\"Platform\"]\n        direction TB\n        Tokens[\"Token Estimation\"]\n        Storage[\"Storage\"]\n        Config[\"Config Snapshot\"]\n        Auth[\"Auth\"]\n        Log[\"Logging\"]\n    end\n\n    API --> OpenAI\n    API --> Anthropic\n    API --> Web\n\n    OpenAI --> Models\n    OpenAI --> AccountDP\n    OpenAI --> ProxyDP\n    OpenAI --> Reverse\n    OpenAI --> Tokens\n    OpenAI --> Storage\n\n    Anthropic --> Models\n    Anthropic --> AccountDP\n    Anthropic --> ProxyDP\n    Anthropic --> Reverse\n    Anthropic --> Tokens\n\n    Web --> Accounts\n    Web --> Config\n    Web --> Auth\n\n    Accounts --> AccountDP\n    Proxies --> ProxyDP\n    Models --> Reverse\n```\n\n\u003Cbr>\n\n## 快速开始\n\n### 本地部署\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fchenyme\u002Fgrok2api\ncd grok2api\ncp .env.example .env\nuv sync\nuv run granian --interface asgi --host 0.0.0.0 --port 8000 --workers 1 app.main:app\n```\n\n### Docker Compose\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fchenyme\u002Fgrok2api\ncd grok2api\ncp .env.example .env\ndocker compose up -d\n```\n\n### Vercel\n\n[![Deploy with Vercel](https:\u002F\u002Fvercel.com\u002Fbutton)](https:\u002F\u002Fvercel.com\u002Fnew\u002Fclone?repository-url=https:\u002F\u002Fgithub.com\u002Fchenyme\u002Fgrok2api&env=LOG_LEVEL,LOG_FILE_ENABLED,DATA_DIR,LOG_DIR,ACCOUNT_STORAGE,ACCOUNT_REDIS_URL,ACCOUNT_MYSQL_URL,ACCOUNT_POSTGRESQL_URL)\n\n### Render\n\n[![Deploy to Render](https:\u002F\u002Frender.com\u002Fimages\u002Fdeploy-to-render-button.svg)](https:\u002F\u002Frender.com\u002Fdeploy?repo=https:\u002F\u002Fgithub.com\u002Fchenyme\u002Fgrok2api)\n\n### 首次启动\n\n1. 修改 `app.app_key`\n2. 设置 `app.api_key`\n3. 设置 `app.app_url`（否则图片、视频的链接会 403 无权访问）\n\n\u003Cbr>\n\n## WebUI\n\n### 页面入口\n\n| 页面 | 路径 |\n| :-- | :-- |\n| Admin 登录页 | `\u002Fadmin\u002Flogin` |\n| 账号管理 | `\u002Fadmin\u002Faccount` |\n| 配置管理 | `\u002Fadmin\u002Fconfig` |\n| 缓存管理 | `\u002Fadmin\u002Fcache` |\n| WebUI 登录页 | `\u002Fwebui\u002Flogin` |\n| Web Chat | `\u002Fwebui\u002Fchat` |\n| Masonry | `\u002Fwebui\u002Fmasonry` |\n| ChatKit | `\u002Fwebui\u002Fchatkit` |\n\n### 鉴权规则\n\n| 范围 | 配置项 | 规则 |\n| :-- | :-- | :-- |\n| `\u002Fv1\u002F*` | `app.api_key` | 为空则不额外鉴权 |\n| `\u002Fadmin\u002F*` | `app.app_key` | 默认值 `grok2api` |\n| `\u002Fwebui\u002F*` | `app.webui_enabled`, `app.webui_key` | 默认关闭；`webui_key` 为空则不额外校验 |\n\n\u003Cbr>\n\n## 配置体系\n\n### 配置分层\n\n| 位置 | 用途 | 生效时机 |\n| :-- | :-- | :-- |\n| `.env` | 启动前配置 | 服务启动时 |\n| `${DATA_DIR}\u002Fconfig.toml` | 运行时配置 | 保存后即时生效 |\n| `config.defaults.toml` | 默认模板 | 首次初始化时 |\n\n\n\n### 环境变量\n\n| 变量名 | 说明 | 默认值 |\n| :-- | :-- | :-- |\n| `TZ` | 时区 | `Asia\u002FShanghai` |\n| `LOG_LEVEL` | 日志级别 | `INFO` |\n| `LOG_FILE_ENABLED` | 写入本地文件日志 | `true` |\n| `ACCOUNT_SYNC_INTERVAL` | 账号目录增量同步间隔（秒） | `30` |\n| `ACCOUNT_SYNC_ACTIVE_INTERVAL` | 账号目录检测到变化后的活跃同步间隔（秒） | `3` |\n| `SERVER_HOST` | 服务监听地址 | `0.0.0.0` |\n| `SERVER_PORT` | 服务监听端口 | `8000` |\n| `SERVER_WORKERS` | Granian worker 数量 | `1` |\n| `HOST_PORT` | Docker Compose 宿主机映射端口 | `8000` |\n| `DATA_DIR` | 本地数据根目录（账号库、本地媒体文件、缓存索引统一位于此目录下） | `.\u002Fdata` |\n| `LOG_DIR` | 本地日志目录 | `.\u002Flogs` |\n| `ACCOUNT_STORAGE` | 账号存储后端 | `local` |\n| `ACCOUNT_LOCAL_PATH` | `local` 模式账号 SQLite 路径 | `${DATA_DIR}\u002Faccounts.db` |\n| `ACCOUNT_REDIS_URL` | `redis` 模式 Redis DSN | `\"\"` |\n| `ACCOUNT_MYSQL_URL` | `mysql` 模式 SQLAlchemy DSN | `\"\"` |\n| `ACCOUNT_POSTGRESQL_URL` | `postgresql` 模式 SQLAlchemy DSN | `\"\"` |\n| `ACCOUNT_SQL_POOL_SIZE` | SQL 连接池核心连接数 | `5` |\n| `ACCOUNT_SQL_MAX_OVERFLOW` | SQL 连接池最大溢出连接数 | `10` |\n| `ACCOUNT_SQL_POOL_TIMEOUT` | 等待连接池空闲连接的超时时间（秒） | `30` |\n| `ACCOUNT_SQL_POOL_RECYCLE` | 连接最大复用时间（秒），超时后自动重连 | `1800` |\n| `CONFIG_LOCAL_PATH` | `local` 模式运行时配置文件路径 | `${DATA_DIR}\u002Fconfig.toml` |\n\n运行时配置也支持 `GROK_` 前缀环境变量覆盖，例如 `GROK_APP_API_KEY` 会覆盖 `app.api_key`，`GROK_FEATURES_STREAM` 会覆盖 `features.stream`。\n\n### 系统配置项\n\n| 分组 | 关键项 |\n| :-- | :-- |\n| `app` | `app_key`, `app_url`, `api_key`, `webui_enabled`, `webui_key` |\n| `logging` | `file_level`, `max_files` |\n| `features` | `temporary`, `memory`, `stream`, `thinking`, `auto_chat_mode_fallback`, `thinking_summary`, `dynamic_statsig`, `enable_nsfw`, `show_search_sources`, `custom_instruction`, `image_format`, `imagine_public_image_proxy`, `video_format` |\n| `proxy.egress` | `mode`, `proxy_url`, `proxy_pool`, `resource_proxy_url`, `resource_proxy_pool`, `skip_ssl_verify` |\n| `proxy.clearance` | `mode`, `cf_cookies`, `user_agent`, `browser`, `flaresolverr_url`, `timeout_sec`, `refresh_interval` |\n| `retry` | `reset_session_status_codes`, `max_retries`, `on_codes` |\n| `account.refresh` | `basic_interval_sec`, `super_interval_sec`, `heavy_interval_sec`, `usage_concurrency`, `on_demand_min_interval_sec` |\n| `cache.local` | `image_max_mb`, `video_max_mb` |\n| `chat` | `timeout` |\n| `image` | `timeout`, `stream_timeout` |\n| `video` | `timeout` |\n| `voice` | `timeout` |\n| `asset` | `upload_timeout`, `download_timeout`, `list_timeout`, `delete_timeout` |\n| `nsfw` | `timeout` |\n| `batch` | `nsfw_concurrency`, `refresh_concurrency`, `asset_upload_concurrency`, `asset_list_concurrency`, `asset_delete_concurrency` |\n\n### 图片、视频格式\n\n| 配置项 | 可选值 |\n| :-- | :-- |\n| `features.image_format` | `grok_url`, `local_url`, `grok_md`, `local_md`, `base64` |\n| `features.imagine_public_image_proxy` | `true`, `false` |\n| `features.video_format` | `grok_url`, `local_url`, `grok_html`, `local_html` |\n\n\u003Cbr>\n\n## 模型支持\n> 可通过 `GET \u002Fv1\u002Fmodels` 获取当前支持模型列表。\n\n### Chat\n\n| 模型名 | mode | tier |\n| :-- | :-- | :-- |\n| `grok-4.20-0309-non-reasoning` | `fast` | `basic` |\n| `grok-4.20-0309` | `auto` | `super` |\n| `grok-4.20-0309-reasoning` | `expert` | `super` |\n| `grok-4.20-0309-non-reasoning-super` | `fast` | `super` |\n| `grok-4.20-0309-super` | `auto` | `super` |\n| `grok-4.20-0309-reasoning-super` | `expert` | `super` |\n| `grok-4.20-0309-non-reasoning-heavy` | `fast` | `heavy` |\n| `grok-4.20-0309-heavy` | `auto` | `heavy` |\n| `grok-4.20-0309-reasoning-heavy` | `expert` | `heavy` |\n| `grok-4.20-multi-agent-0309` | `heavy` | `heavy` |\n| `grok-4.20-fast` | `fast` | `basic`，优先使用高等级账号池 |\n| `grok-4.20-auto` | `auto` | `super`，优先使用高等级账号池 |\n| `grok-4.20-expert` | `expert` | `super`，优先使用高等级账号池 |\n| `grok-4.20-heavy` | `heavy` | `heavy` |\n| `grok-4.3-beta` | `grok-420-computer-use-sa` | `super` |\n\n### Image\n\n| 模型名 | mode | tier |\n| :-- | :-- | :-- |\n| `grok-imagine-image-lite` | `fast` | `basic` |\n| `grok-imagine-image` | `auto` | `super` |\n| `grok-imagine-image-pro` | `auto` | `super` |\n\n### Image Edit\n\n| 模型名 | mode | tier |\n| :-- | :-- | :-- |\n| `grok-imagine-image-edit` | `auto` | `super` |\n\n### Video\n\n| 模型名 | mode | tier |\n| :-- | :-- | :-- |\n| `grok-imagine-video` | `auto` | `super` |\n\n\u003Cbr>\n\n## API 一览\n\n| 接口 | 是否鉴权 | 说明 |\n| :-- | :-- | :-- |\n| `GET \u002Fv1\u002Fmodels` | 是 | 列出当前启用模型 |\n| `GET \u002Fv1\u002Fmodels\u002F{model_id}` | 是 | 获取单个模型信息 |\n| `POST \u002Fv1\u002Fchat\u002Fcompletions` | 是 | 对话 \u002F 图像 \u002F 视频统一入口 |\n| `POST \u002Fv1\u002Fresponses` | 是 | OpenAI Responses API 兼容子集 |\n| `POST \u002Fv1\u002Fmessages` | 是 | Anthropic Messages API 兼容接口 |\n| `POST \u002Fv1\u002Fimages\u002Fgenerations` | 是 | 独立图像生成接口 |\n| `POST \u002Fv1\u002Fimages\u002Fedits` | 是 | 独立图像编辑接口 |\n| `POST \u002Fv1\u002Fvideos` | 是 | 异步视频任务创建 |\n| `GET \u002Fv1\u002Fvideos\u002F{video_id}` | 是 | 查询视频任务 |\n| `GET \u002Fv1\u002Fvideos\u002F{video_id}\u002Fcontent` | 是 | 获取最终视频文件 |\n| `GET \u002Fv1\u002Ffiles\u002Fvideo?id=...` | 否 | 获取本地缓存视频 |\n| `GET \u002Fv1\u002Ffiles\u002Fimage?id=...` | 否 | 获取本地缓存图片 |\n\n\u003Cbr>\n\n## 接口示例\n\n> 以下示例默认使用 `http:\u002F\u002Flocalhost:8000` 地址。\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>GET \u002Fv1\u002Fmodels\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fmodels \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\"\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 位置 | 说明 |\n| :-- | :-- | :-- |\n| `Authorization` | Header | 当 `app.api_key` 非空时必填，格式为 `Bearer \u003Capi_key>` |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fchat\u002Fcompletions\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n对话：\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-4.20-auto\",\n    \"stream\": true,\n    \"reasoning_effort\": \"high\",\n    \"messages\": [\n      {\"role\":\"user\",\"content\":\"你好\"}\n    ]\n  }'\n```\n\n图像：\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-imagine-image\",\n    \"stream\": true,\n    \"messages\": [\n      {\"role\":\"user\",\"content\":\"一只在太空漂浮的猫\"}\n    ],\n    \"image_config\": {\n      \"n\": 2,\n      \"size\": \"1024x1024\",\n      \"response_format\": \"url\"\n    }\n  }'\n```\n\n视频：\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fchat\u002Fcompletions \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-imagine-video\",\n    \"stream\": true,\n    \"messages\": [\n      {\"role\":\"user\",\"content\":\"霓虹雨夜街头，电影感慢镜头追拍\"}\n    ],\n    \"video_config\": {\n      \"seconds\": 10,\n      \"size\": \"1792x1024\",\n      \"resolution_name\": \"720p\",\n      \"preset\": \"normal\"\n    }\n  }'\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `messages` | 支持文本与多模态内容块 |\n| `stream` | 是否流式输出；不传时使用 `features.stream` 默认值 |\n| `reasoning_effort` | `none`, `minimal`, `low`, `medium`, `high`, `xhigh`；`none` 会关闭思考输出 |\n| `temperature` \u002F `top_p` | 采样参数，默认 `0.8` \u002F `0.95` |\n| `tools` | OpenAI function tools 结构 |\n| `tool_choice` | `auto`, `required` 或指定函数工具 |\n| `image_config` | 图像模型参数 |\n| \\|_ `n` | `lite` 为 `1-4`，其他图像模型为 `1-10`，编辑模型为 `1-2` |\n| \\|_ `size` | `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |\n| \\|_ `response_format` | `url`, `b64_json` |\n| `video_config` | 视频模型参数 |\n| \\|_ `seconds` | `6`, `10`, `12`, `16`, `20` |\n| \\|_ `size` | `720x1280`, `1280x720`, `1024x1024`, `1024x1792`, `1792x1024` |\n| \\|_ `resolution_name` | `480p`, `720p` |\n| \\|_ `preset` | `fun`, `normal`, `spicy`, `custom` |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fresponses\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fresponses \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-4.20-auto\",\n    \"input\": \"解释一下量子隧穿\",\n    \"instructions\": \"用简洁的中文回答\",\n    \"stream\": true,\n    \"reasoning\": {\n      \"effort\": \"high\"\n    }\n  }'\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `model` | 模型 ID，需为已启用模型 |\n| `input` | 用户输入；支持字符串或 Responses API 风格的消息数组 |\n| `instructions` | 可选系统指令，会作为 system 消息注入 |\n| `stream` | 是否流式输出；不传时使用 `features.stream` 默认值 |\n| `reasoning` | 可选思考配置 |\n| \\|_ `effort` | `none` 会关闭思考输出；其他值会开启思考输出 |\n| `temperature` \u002F `top_p` | 采样参数，默认 `0.8` \u002F `0.95` |\n| `tools` \u002F `tool_choice` | 支持函数工具；Responses API 的扁平工具格式会自动转换 |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fmessages\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fmessages \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-4.20-auto\",\n    \"stream\": true,\n    \"thinking\": {\n      \"type\": \"enabled\",\n      \"budget_tokens\": 1024\n    },\n    \"messages\": [\n      {\n        \"role\": \"user\",\n        \"content\": \"用三句话解释量子隧穿\"\n      }\n    ]\n  }'\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `model` | 模型 ID，需为已启用模型 |\n| `messages` | Anthropic Messages 格式消息，支持文本、图片、文档和工具结果块 |\n| `system` | 可选系统提示词，支持字符串或文本块数组 |\n| `stream` | 是否流式输出；不传时使用 `features.stream` 默认值 |\n| `thinking` | 可选思考配置 |\n| \\|_ `type` | `disabled` 会关闭思考输出；其他配置会开启思考输出 |\n| `max_tokens` | 接收但当前会忽略，Grok 上游不暴露该参数 |\n| `tools` \u002F `tool_choice` | 支持 Anthropic 工具格式，会转换为内部 function tools |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fimages\u002Fgenerations\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fimages\u002Fgenerations \\\n  -H \"Content-Type: application\u002Fjson\" \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -d '{\n    \"model\": \"grok-imagine-image\",\n    \"prompt\": \"一只在太空漂浮的猫\",\n    \"n\": 1,\n    \"size\": \"1792x1024\",\n    \"response_format\": \"url\"\n  }'\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `model` | 图像模型：`grok-imagine-image-lite`, `grok-imagine-image`, `grok-imagine-image-pro` |\n| `prompt` | 图片生成提示词 |\n| `n` | 生成数量；`lite` 为 `1-4`，其他图像模型为 `1-10` |\n| `size` | 支持 `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |\n| `response_format` | `url` 或 `b64_json` |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fimages\u002Fedits\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fimages\u002Fedits \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -F \"model=grok-imagine-image-edit\" \\\n  -F \"prompt=把这张图变清晰一些\" \\\n  -F \"image[]=@\u002Fpath\u002Fto\u002Fimage.png\" \\\n  -F \"n=1\" \\\n  -F \"size=1024x1024\" \\\n  -F \"response_format=url\"\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `model` | 图像编辑模型，目前为 `grok-imagine-image-edit` |\n| `prompt` | 编辑指令 |\n| `image[]` | 参考图片，multipart 文件字段；最多使用 5 张 |\n| `n` | 生成数量，范围 `1-2` |\n| `size` | 当前仅支持 `1024x1024` |\n| `response_format` | `url` 或 `b64_json` |\n| `mask` | 暂不支持；传入会返回校验错误 |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cdetails>\n\u003Csummary>\u003Ccode>POST \u002Fv1\u002Fvideos\u003C\u002Fcode>\u003C\u002Fsummary>\n\u003Cbr>\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fvideos \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -F \"model=grok-imagine-video\" \\\n  -F \"prompt=霓虹雨夜街头，电影感慢镜头追拍\" \\\n  -F \"seconds=10\" \\\n  -F \"size=1792x1024\" \\\n  -F \"resolution_name=720p\" \\\n  -F \"preset=normal\" \\\n  -F \"input_reference[]=@\u002Fpath\u002Fto\u002Freference.png\"\n```\n\n```bash\ncurl http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fvideos\u002F\u003Cvideo_id> \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\"\n\ncurl -L http:\u002F\u002Flocalhost:8000\u002Fv1\u002Fvideos\u002F\u003Cvideo_id>\u002Fcontent \\\n  -H \"Authorization: Bearer $GROK2API_API_KEY\" \\\n  -o result.mp4\n```\n\n\u003Cdetails>\n\u003Csummary>字段说明\u003C\u002Fsummary>\n\u003Cbr>\n\n| 字段 | 说明 |\n| :-- | :-- |\n| `model` | 视频模型，目前为 `grok-imagine-video` |\n| `prompt` | 视频生成提示词 |\n| `seconds` | 视频长度：`6`, `10`, `12`, `16`, `20` |\n| `size` | 支持 `720x1280`, `1280x720`, `1024x1024`, `1024x1792`, `1792x1024` |\n| `resolution_name` | `480p` 或 `720p` |\n| `preset` | `fun`, `normal`, `spicy`, `custom` |\n| `input_reference[]` | 可选图生视频参考图，multipart 文件字段；最多使用前 7 张 |\n| `video_id` | `POST \u002Fv1\u002Fvideos` 返回的视频任务 ID，用于查询任务或下载成片 |\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\u003C\u002Fdetails>\n\n\u003Cbr>\n\n## Star History\n\n[![Star History Chart](https:\u002F\u002Fapi.star-history.com\u002Fsvg?repos=Chenyme\u002Fgrok2api&type=Timeline)](https:\u002F\u002Fstar-history.com\u002F#Chenyme\u002Fgrok2api&Timeline)\n","Grok2API 是一个基于 FastAPI 构建的 Grok 网关，支持将 Grok Web 能力以 OpenAI 兼容 API 的方式转换。其核心功能包括提供与 OpenAI 和 Anthropic 兼容的接口，支持流式与非流式对话、显式思考输出、函数工具结构透传及统一的 token\u002Fusage 统计。此外，它还支持多账号池管理、本地缓存媒体文件以及文生图、图像编辑、文生视频等多媒体处理能力，并内置了 Admin 后台管理和多种前端页面。此项目适用于需要将 Grok 功能集成到现有系统中，或者希望使用标准 API 接口访问 Grok 服务的场景。",2,"2026-06-11 03:40:29","high_star"]