You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 17 KiB

4 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. <div align="center">
  2. ![new-api](/web/public/logo.png)
  3. # New API
  4. 🍥 **Next-Generation LLM Gateway and AI Asset Management System**
  5. <p align="center">
  6. <a href="./README.zh_CN.md">简体中文</a> |
  7. <a href="./README.zh_TW.md">繁體中文</a> |
  8. <strong>English</strong> |
  9. <a href="./README.fr.md">Français</a> |
  10. <a href="./README.ja.md">日本語</a>
  11. </p>
  12. <p align="center">
  13. <a href="https://raw.githubusercontent.com/Calcium-Ion/new-api/main/LICENSE">
  14. <img src="https://img.shields.io/github/license/Calcium-Ion/new-api?color=brightgreen" alt="license">
  15. </a><!--
  16. --><a href="https://github.com/Calcium-Ion/new-api/releases/latest">
  17. <img src="https://img.shields.io/github/v/release/Calcium-Ion/new-api?color=brightgreen&include_prereleases" alt="release">
  18. </a><!--
  19. --><a href="https://hub.docker.com/r/CalciumIon/new-api">
  20. <img src="https://img.shields.io/badge/docker-dockerHub-blue" alt="docker">
  21. </a><!--
  22. --><a href="https://goreportcard.com/report/github.com/Calcium-Ion/new-api">
  23. <img src="https://goreportcard.com/badge/github.com/Calcium-Ion/new-api" alt="GoReportCard">
  24. </a>
  25. </p>
  26. <p align="center">
  27. <a href="https://trendshift.io/repositories/20180" target="_blank">
  28. <img src="https://trendshift.io/api/badge/repositories/20180" alt="QuantumNous%2Fnew-api | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/>
  29. </a>
  30. <br>
  31. <a href="https://hellogithub.com/repository/QuantumNous/new-api" target="_blank">
  32. <img src="https://api.hellogithub.com/v1/widgets/recommend.svg?rid=539ac4217e69431684ad4a0bab768811&claim_uid=tbFPfKIDHpc4TzR" alt="Featured|HelloGitHub" style="width: 250px; height: 54px;" width="250" height="54" />
  33. </a><!--
  34. --><a href="https://www.producthunt.com/products/new-api/launches/new-api?embed=true&utm_source=badge-featured&utm_medium=badge&utm_campaign=badge-new-api" target="_blank" rel="noopener noreferrer">
  35. <img src="https://api.producthunt.com/widgets/embed-image/v1/featured.svg?post_id=1047693&theme=light&t=1769577875005" alt="New API - All-in-one AI asset management gateway. | Product Hunt" style="width: 250px; height: 54px;" width="250" height="54" />
  36. </a>
  37. </p>
  38. <p align="center">
  39. <a href="#-quick-start">Quick Start</a> •
  40. <a href="#-key-features">Key Features</a> •
  41. <a href="#-deployment">Deployment</a> •
  42. <a href="#-documentation">Documentation</a> •
  43. <a href="#-help-support">Help</a>
  44. </p>
  45. </div>
  46. ## 📝 Project Description
  47. > [!IMPORTANT]
  48. > - This project is for personal learning purposes only, with no guarantee of stability or technical support
  49. > - Users must comply with OpenAI's [Terms of Use](https://openai.com/policies/terms-of-use) and **applicable laws and regulations**, and must not use it for illegal purposes
  50. > - According to the [《Interim Measures for the Management of Generative Artificial Intelligence Services》](http://www.cac.gov.cn/2023-07/13/c_1690898327029107.htm), please do not provide any unregistered generative AI services to the public in China.
  51. ---
  52. ## 🤝 Trusted Partners
  53. <p align="center">
  54. <em>No particular order</em>
  55. </p>
  56. <p align="center">
  57. <a href="https://www.cherry-ai.com/" target="_blank">
  58. <img src="./docs/images/cherry-studio.png" alt="Cherry Studio" height="80" />
  59. </a><!--
  60. --><a href="https://github.com/iOfficeAI/AionUi/" target="_blank">
  61. <img src="./docs/images/aionui.png" alt="Aion UI" height="80" />
  62. </a><!--
  63. --><a href="https://bda.pku.edu.cn/" target="_blank">
  64. <img src="./docs/images/pku.png" alt="Peking University" height="80" />
  65. </a><!--
  66. --><a href="https://www.compshare.cn/?ytag=GPU_yy_gh_newapi" target="_blank">
  67. <img src="./docs/images/ucloud.png" alt="UCloud" height="80" />
  68. </a><!--
  69. --><a href="https://www.aliyun.com/" target="_blank">
  70. <img src="./docs/images/aliyun.png" alt="Alibaba Cloud" height="80" />
  71. </a><!--
  72. --><a href="https://io.net/" target="_blank">
  73. <img src="./docs/images/io-net.png" alt="IO.NET" height="80" />
  74. </a>
  75. </p>
  76. ---
  77. ## 🙏 Special Thanks
  78. <p align="center">
  79. <a href="https://www.jetbrains.com/?from=new-api" target="_blank">
  80. <img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jb_beam.png" alt="JetBrains Logo" width="120" />
  81. </a>
  82. </p>
  83. <p align="center">
  84. <strong>Thanks to <a href="https://www.jetbrains.com/?from=new-api">JetBrains</a> for providing free open-source development license for this project</strong>
  85. </p>
  86. ---
  87. ## 🚀 Quick Start
  88. ### Using Docker Compose (Recommended)
  89. ```bash
  90. # Clone the project
  91. git clone https://github.com/QuantumNous/new-api.git
  92. cd new-api
  93. # Edit docker-compose.yml configuration
  94. nano docker-compose.yml
  95. # Start the service
  96. docker-compose up -d
  97. ```
  98. <details>
  99. <summary><strong>Using Docker Commands</strong></summary>
  100. ```bash
  101. # Pull the latest image
  102. docker pull calciumion/new-api:latest
  103. # Using SQLite (default)
  104. docker run --name new-api -d --restart always \
  105. -p 3000:3000 \
  106. -e TZ=Asia/Shanghai \
  107. -v ./data:/data \
  108. calciumion/new-api:latest
  109. # Using MySQL
  110. docker run --name new-api -d --restart always \
  111. -p 3000:3000 \
  112. -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" \
  113. -e TZ=Asia/Shanghai \
  114. -v ./data:/data \
  115. calciumion/new-api:latest
  116. ```
  117. > **💡 Tip:** `-v ./data:/data` will save data in the `data` folder of the current directory, you can also change it to an absolute path like `-v /your/custom/path:/data`
  118. </details>
  119. ---
  120. 🎉 After deployment is complete, visit `http://localhost:3000` to start using!
  121. 📖 For more deployment methods, please refer to [Deployment Guide](https://docs.newapi.pro/en/docs/installation)
  122. ---
  123. ## 📚 Documentation
  124. <div align="center">
  125. ### 📖 [Official Documentation](https://docs.newapi.pro/en/docs) | [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/QuantumNous/new-api)
  126. </div>
  127. **Quick Navigation:**
  128. | Category | Link |
  129. |------|------|
  130. | 🚀 Deployment Guide | [Installation Documentation](https://docs.newapi.pro/en/docs/installation) |
  131. | ⚙️ Environment Configuration | [Environment Variables](https://docs.newapi.pro/en/docs/installation/config-maintenance/environment-variables) |
  132. | 📡 API Documentation | [API Documentation](https://docs.newapi.pro/en/docs/api) |
  133. | ❓ FAQ | [FAQ](https://docs.newapi.pro/en/docs/support/faq) |
  134. | 💬 Community Interaction | [Communication Channels](https://docs.newapi.pro/en/docs/support/community-interaction) |
  135. ---
  136. ## ✨ Key Features
  137. > For detailed features, please refer to [Features Introduction](https://docs.newapi.pro/en/docs/guide/wiki/basic-concepts/features-introduction)
  138. ### 🎨 Core Functions
  139. | Feature | Description |
  140. |------|------|
  141. | 🎨 New UI | Modern user interface design |
  142. | 🌍 Multi-language | Supports Simplified Chinese, Traditional Chinese, English, French, Japanese |
  143. | 🔄 Data Compatibility | Fully compatible with the original One API database |
  144. | 📈 Data Dashboard | Visual console and statistical analysis |
  145. | 🔒 Permission Management | Token grouping, model restrictions, user management |
  146. ### 💰 Payment and Billing
  147. - ✅ Online recharge (EPay, Stripe)
  148. - ✅ Pay-per-use model pricing
  149. - ✅ Cache billing support (OpenAI, Azure, DeepSeek, Claude, Qwen and all supported models)
  150. - ✅ Flexible billing policy configuration
  151. ### 🔐 Authorization and Security
  152. - 😈 Discord authorization login
  153. - 🤖 LinuxDO authorization login
  154. - 📱 Telegram authorization login
  155. - 🔑 OIDC unified authentication
  156. - 🔍 Key quota query usage (with [neko-api-key-tool](https://github.com/Calcium-Ion/neko-api-key-tool))
  157. ### 🚀 Advanced Features
  158. **API Format Support:**
  159. - ⚡ [OpenAI Responses](https://docs.newapi.pro/en/docs/api/ai-model/chat/openai/create-response)
  160. - ⚡ [OpenAI Realtime API](https://docs.newapi.pro/en/docs/api/ai-model/realtime/create-realtime-session) (including Azure)
  161. - ⚡ [Claude Messages](https://docs.newapi.pro/en/docs/api/ai-model/chat/create-message)
  162. - ⚡ [Google Gemini](https://doc.newapi.pro/en/api/google-gemini-chat)
  163. - 🔄 [Rerank Models](https://docs.newapi.pro/en/docs/api/ai-model/rerank/create-rerank) (Cohere, Jina)
  164. **Intelligent Routing:**
  165. - ⚖️ Channel weighted random
  166. - 🔄 Automatic retry on failure
  167. - 🚦 User-level model rate limiting
  168. **Format Conversion:**
  169. - 🔄 **OpenAI Compatible ⇄ Claude Messages**
  170. - 🔄 **OpenAI Compatible → Google Gemini**
  171. - 🔄 **Google Gemini → OpenAI Compatible** - Text only, function calling not supported yet
  172. - 🚧 **OpenAI Compatible ⇄ OpenAI Responses** - In development
  173. - 🔄 **Thinking-to-content functionality**
  174. **Reasoning Effort Support:**
  175. <details>
  176. <summary>View detailed configuration</summary>
  177. **OpenAI series models:**
  178. - `o3-mini-high` - High reasoning effort
  179. - `o3-mini-medium` - Medium reasoning effort
  180. - `o3-mini-low` - Low reasoning effort
  181. - `gpt-5-high` - High reasoning effort
  182. - `gpt-5-medium` - Medium reasoning effort
  183. - `gpt-5-low` - Low reasoning effort
  184. **Claude thinking models:**
  185. - `claude-3-7-sonnet-20250219-thinking` - Enable thinking mode
  186. **Google Gemini series models:**
  187. - `gemini-2.5-flash-thinking` - Enable thinking mode
  188. - `gemini-2.5-flash-nothinking` - Disable thinking mode
  189. - `gemini-2.5-pro-thinking` - Enable thinking mode
  190. - `gemini-2.5-pro-thinking-128` - Enable thinking mode with thinking budget of 128 tokens
  191. - You can also append `-low`, `-medium`, or `-high` to any Gemini model name to request the corresponding reasoning effort (no extra thinking-budget suffix needed).
  192. </details>
  193. ---
  194. ## 🤖 Model Support
  195. > For details, please refer to [API Documentation - Relay Interface](https://docs.newapi.pro/en/docs/api)
  196. | Model Type | Description | Documentation |
  197. |---------|------|------|
  198. | 🤖 OpenAI-Compatible | OpenAI compatible models | [Documentation](https://docs.newapi.pro/en/docs/api/ai-model/chat/openai/createchatcompletion) |
  199. | 🤖 OpenAI Responses | OpenAI Responses format | [Documentation](https://docs.newapi.pro/en/docs/api/ai-model/chat/openai/createresponse) |
  200. | 🎨 Midjourney-Proxy | [Midjourney-Proxy(Plus)](https://github.com/novicezk/midjourney-proxy) | [Documentation](https://doc.newapi.pro/api/midjourney-proxy-image) |
  201. | 🎵 Suno-API | [Suno API](https://github.com/Suno-API/Suno-API) | [Documentation](https://doc.newapi.pro/api/suno-music) |
  202. | 🔄 Rerank | Cohere, Jina | [Documentation](https://docs.newapi.pro/en/docs/api/ai-model/rerank/creatererank) |
  203. | 💬 Claude | Messages format | [Documentation](https://docs.newapi.pro/en/docs/api/ai-model/chat/createmessage) |
  204. | 🌐 Gemini | Google Gemini format | [Documentation](https://docs.newapi.pro/en/docs/api/ai-model/chat/gemini/geminirelayv1beta) |
  205. | 🔧 Dify | ChatFlow mode | - |
  206. | 🎯 Custom | Supports complete call address | - |
  207. ### 📡 Supported Interfaces
  208. <details>
  209. <summary>View complete interface list</summary>
  210. - [Chat Interface (Chat Completions)](https://docs.newapi.pro/en/docs/api/ai-model/chat/openai/createchatcompletion)
  211. - [Response Interface (Responses)](https://docs.newapi.pro/en/docs/api/ai-model/chat/openai/createresponse)
  212. - [Image Interface (Image)](https://docs.newapi.pro/en/docs/api/ai-model/images/openai/post-v1-images-generations)
  213. - [Audio Interface (Audio)](https://docs.newapi.pro/en/docs/api/ai-model/audio/openai/create-transcription)
  214. - [Video Interface (Video)](https://docs.newapi.pro/en/docs/api/ai-model/audio/openai/createspeech)
  215. - [Embedding Interface (Embeddings)](https://docs.newapi.pro/en/docs/api/ai-model/embeddings/createembedding)
  216. - [Rerank Interface (Rerank)](https://docs.newapi.pro/en/docs/api/ai-model/rerank/creatererank)
  217. - [Realtime Conversation (Realtime)](https://docs.newapi.pro/en/docs/api/ai-model/realtime/createrealtimesession)
  218. - [Claude Chat](https://docs.newapi.pro/en/docs/api/ai-model/chat/createmessage)
  219. - [Google Gemini Chat](https://docs.newapi.pro/en/docs/api/ai-model/chat/gemini/geminirelayv1beta)
  220. </details>
  221. ---
  222. ## 🚢 Deployment
  223. > [!TIP]
  224. > **Latest Docker image:** `calciumion/new-api:latest`
  225. ### 📋 Deployment Requirements
  226. | Component | Requirement |
  227. |------|------|
  228. | **Local database** | SQLite (Docker must mount `/data` directory)|
  229. | **Remote database** | MySQL ≥ 5.7.8 or PostgreSQL ≥ 9.6 |
  230. | **Container engine** | Docker / Docker Compose |
  231. ### ⚙️ Environment Variable Configuration
  232. <details>
  233. <summary>Common environment variable configuration</summary>
  234. | Variable Name | Description | Default Value |
  235. |--------|------|--------|
  236. | `SESSION_SECRET` | Session secret (required for multi-machine deployment) | - |
  237. | `CRYPTO_SECRET` | Encryption secret (required for Redis) | - |
  238. | `SQL_DSN` | Database connection string | - |
  239. | `REDIS_CONN_STRING` | Redis connection string | - |
  240. | `STREAMING_TIMEOUT` | Streaming timeout (seconds) | `300` |
  241. | `STREAM_SCANNER_MAX_BUFFER_MB` | Max per-line buffer (MB) for the stream scanner; increase when upstream sends huge image/base64 payloads | `64` |
  242. | `MAX_REQUEST_BODY_MB` | Max request body size (MB, counted **after decompression**; prevents huge requests/zip bombs from exhausting memory). Exceeding it returns `413` | `32` |
  243. | `AZURE_DEFAULT_API_VERSION` | Azure API version | `2025-04-01-preview` |
  244. | `ERROR_LOG_ENABLED` | Error log switch | `false` |
  245. | `PYROSCOPE_URL` | Pyroscope server address | - |
  246. | `PYROSCOPE_APP_NAME` | Pyroscope application name | `new-api` |
  247. | `PYROSCOPE_BASIC_AUTH_USER` | Pyroscope basic auth user | - |
  248. | `PYROSCOPE_BASIC_AUTH_PASSWORD` | Pyroscope basic auth password | - |
  249. | `PYROSCOPE_MUTEX_RATE` | Pyroscope mutex sampling rate | `5` |
  250. | `PYROSCOPE_BLOCK_RATE` | Pyroscope block sampling rate | `5` |
  251. | `HOSTNAME` | Hostname tag for Pyroscope | `new-api` |
  252. 📖 **Complete configuration:** [Environment Variables Documentation](https://docs.newapi.pro/en/docs/installation/config-maintenance/environment-variables)
  253. </details>
  254. ### 🔧 Deployment Methods
  255. <details>
  256. <summary><strong>Method 1: Docker Compose (Recommended)</strong></summary>
  257. ```bash
  258. # Clone the project
  259. git clone https://github.com/QuantumNous/new-api.git
  260. cd new-api
  261. # Edit configuration
  262. nano docker-compose.yml
  263. # Start service
  264. docker-compose up -d
  265. ```
  266. </details>
  267. <details>
  268. <summary><strong>Method 2: Docker Commands</strong></summary>
  269. **Using SQLite:**
  270. ```bash
  271. docker run --name new-api -d --restart always \
  272. -p 3000:3000 \
  273. -e TZ=Asia/Shanghai \
  274. -v ./data:/data \
  275. calciumion/new-api:latest
  276. ```
  277. **Using MySQL:**
  278. ```bash
  279. docker run --name new-api -d --restart always \
  280. -p 3000:3000 \
  281. -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" \
  282. -e TZ=Asia/Shanghai \
  283. -v ./data:/data \
  284. calciumion/new-api:latest
  285. ```
  286. > **💡 Path explanation:**
  287. > - `./data:/data` - Relative path, data saved in the data folder of the current directory
  288. > - You can also use absolute path, e.g.: `/your/custom/path:/data`
  289. </details>
  290. <details>
  291. <summary><strong>Method 3: BaoTa Panel</strong></summary>
  292. 1. Install BaoTa Panel (≥ 9.2.0 version)
  293. 2. Search for **New-API** in the application store
  294. 3. One-click installation
  295. 📖 [Tutorial with images](./docs/BT.md)
  296. </details>
  297. ### ⚠️ Multi-machine Deployment Considerations
  298. > [!WARNING]
  299. > - **Must set** `SESSION_SECRET` - Otherwise login status inconsistent
  300. > - **Shared Redis must set** `CRYPTO_SECRET` - Otherwise data cannot be decrypted
  301. ### 🔄 Channel Retry and Cache
  302. **Retry configuration:** `Settings → Operation Settings → General Settings → Failure Retry Count`
  303. **Cache configuration:**
  304. - `REDIS_CONN_STRING`: Redis cache (recommended)
  305. - `MEMORY_CACHE_ENABLED`: Memory cache
  306. ---
  307. ## 🔗 Related Projects
  308. ### Upstream Projects
  309. | Project | Description |
  310. |------|------|
  311. | [One API](https://github.com/songquanpeng/one-api) | Original project base |
  312. | [Midjourney-Proxy](https://github.com/novicezk/midjourney-proxy) | Midjourney interface support |
  313. ### Supporting Tools
  314. | Project | Description |
  315. |------|------|
  316. | [neko-api-key-tool](https://github.com/Calcium-Ion/neko-api-key-tool) | Key quota query tool |
  317. | [new-api-horizon](https://github.com/Calcium-Ion/new-api-horizon) | New API high-performance optimized version |
  318. ---
  319. ## 💬 Help Support
  320. ### 📖 Documentation Resources
  321. | Resource | Link |
  322. |------|------|
  323. | 📘 FAQ | [FAQ](https://docs.newapi.pro/en/docs/support/faq) |
  324. | 💬 Community Interaction | [Communication Channels](https://docs.newapi.pro/en/docs/support/community-interaction) |
  325. | 🐛 Issue Feedback | [Issue Feedback](https://docs.newapi.pro/en/docs/support/feedback-issues) |
  326. | 📚 Complete Documentation | [Official Documentation](https://docs.newapi.pro/en/docs) |
  327. ### 🤝 Contribution Guide
  328. Welcome all forms of contribution!
  329. - 🐛 Report Bugs
  330. - 💡 Propose New Features
  331. - 📝 Improve Documentation
  332. - 🔧 Submit Code
  333. ---
  334. ## 📜 License
  335. This project is licensed under the [GNU Affero General Public License v3.0 (AGPLv3)](./LICENSE).
  336. This is an open-source project developed based on [One API](https://github.com/songquanpeng/one-api) (MIT License).
  337. If your organization's policies do not permit the use of AGPLv3-licensed software, or if you wish to avoid the open-source obligations of AGPLv3, please contact us at: [support@quantumnous.com](mailto:support@quantumnous.com)
  338. ---
  339. ## 🌟 Star History
  340. <div align="center">
  341. [![Star History Chart](https://api.star-history.com/svg?repos=Calcium-Ion/new-api&type=Date)](https://star-history.com/#Calcium-Ion/new-api&Date)
  342. </div>
  343. ---
  344. <div align="center">
  345. ### 💖 Thank you for using New API
  346. If this project is helpful to you, welcome to give us a ⭐️ Star!
  347. **[Official Documentation](https://docs.newapi.pro/en/docs)** • **[Issue Feedback](https://github.com/Calcium-Ion/new-api/issues)** • **[Latest Release](https://github.com/Calcium-Ion/new-api/releases)**
  348. <sub>Built with ❤️ by QuantumNous</sub>
  349. </div>