diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index dd688493..0ddd31a8 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,26 +1,27 @@ --- -name: 报告问题 -about: 使用简练详细的语言描述你遇到的问题 -title: '' +name: Bug Report +about: Use concise and detailed language to describe the issue you encountered +title: "" labels: bug -assignees: '' - +assignees: "" --- -**例行检查** +## Routine Check -[//]: # (方框内删除已有的空格,填 x 号) -+ [ ] 我已确认目前没有类似 issue -+ [ ] 我已确认我已升级到最新版本 -+ [ ] 我已完整查看过项目 README,尤其是常见问题部分 -+ [ ] 我理解并愿意跟进此 issue,协助测试和提供反馈 -+ [ ] 我理解并认可上述内容,并理解项目维护者精力有限,**不遵循规则的 issue 可能会被无视或直接关闭** +[//]: # "Remove space in brackets and fill with x" -**问题描述** +- [ ] I have confirmed there are no similar issues +- [ ] I have confirmed I am using the latest version +- [ ] I have thoroughly read the project README, especially the FAQ section +- [ ] I understand and am willing to follow up on this issue, assist with testing and provide feedback +- [ ] I understand and agree to the above, and understand that maintainers have limited time - **issues not following guidelines may be ignored or closed** -**复现步骤** +## Issue Description -**预期结果** +## Steps to Reproduce -**相关截图** -如果没有的话,请删除此节。 \ No newline at end of file +## Expected Behavior + +## Screenshots + +Delete this section if not applicable. diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml deleted file mode 100644 index 83a0f3f4..00000000 --- a/.github/ISSUE_TEMPLATE/config.yml +++ /dev/null @@ -1,8 +0,0 @@ -blank_issues_enabled: false -contact_links: - - name: 项目群聊 - url: https://openai.justsong.cn/ - about: QQ 群:828520184,自动审核,备注 One API - - name: 赞赏支持 - url: https://iamazing.cn/page/reward - about: 请作者喝杯咖啡,以激励作者持续开发 diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index 049d89c8..c688f9d1 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,21 +1,21 @@ --- -name: 功能请求 -about: 使用简练详细的语言描述希望加入的新功能 -title: '' +name: Feature Request +about: Use concise and detailed language to describe the new feature you'd like to see +title: "" labels: enhancement -assignees: '' - +assignees: "" --- -**例行检查** +## Routine Check -[//]: # (方框内删除已有的空格,填 x 号) -+ [ ] 我已确认目前没有类似 issue -+ [ ] 我已确认我已升级到最新版本 -+ [ ] 我已完整查看过项目 README,已确定现有版本无法满足需求 -+ [ ] 我理解并愿意跟进此 issue,协助测试和提供反馈 -+ [ ] 我理解并认可上述内容,并理解项目维护者精力有限,**不遵循规则的 issue 可能会被无视或直接关闭** +[//]: # "Remove space in brackets and fill with x" -**功能描述** +- [ ] I have confirmed there are no similar issues +- [ ] I have confirmed I am using the latest version +- [ ] I have thoroughly read the project README and confirmed existing features cannot meet my needs +- [ ] I understand and am willing to follow up on this issue, assist with testing and provide feedback +- [ ] I understand and agree to the above, and understand that maintainers have limited time - **issues not following guidelines may be ignored or closed** -**应用场景** +## Feature Description + +## Use Cases diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 36798711..035abb6d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,47 +1,142 @@ -name: CI +name: ci -# This setup assumes that you run the unit tests with code coverage in the same -# workflow that will also print the coverage report as comment to the pull request. -# Therefore, you need to trigger this workflow when a pull request is (re)opened or -# when new code is pushed to the branch of the pull request. In addition, you also -# need to trigger this workflow when new code is pushed to the main branch because -# we need to upload the code coverage results as artifact for the main branch as -# well since it will be the baseline code coverage. -# -# We do not want to trigger the workflow for pushes to *any* branch because this -# would trigger our jobs twice on pull requests (once from "push" event and once -# from "pull_request->synchronize") on: - pull_request: - types: [opened, reopened, synchronize] push: branches: - - 'main' + - "master" + - "main" + - "test/ci" jobs: - unit_tests: - name: "Unit tests" + build_latest: runs-on: ubuntu-latest steps: - - name: Checkout repository + - name: Checkout uses: actions/checkout@v4 - - name: Setup Go - uses: actions/setup-go@v4 - with: - go-version: ^1.22 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 - # When you execute your unit tests, make sure to use the "-coverprofile" flag to write a - # coverage profile to a file. You will need the name of the file (e.g. "coverage.txt") - # in the next step as well as the next job. - - name: Test - run: go test -cover -coverprofile=coverage.txt ./... - - uses: codecov/codecov-action@v4 - with: - token: ${{ secrets.CODECOV_TOKEN }} + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - commit_lint: + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push latest + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ppcelery/one-api:latest + cache-from: type=gha + # cache-to: type=gha,mode=max + + build_hash: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: wagoid/commitlint-github-action@v6 + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV + + - name: Build and push hash label + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ppcelery/one-api:${{ env.SHORT_SHA }} + cache-from: type=gha + cache-to: type=gha,mode=max + + deploy: + runs-on: ubuntu-latest + needs: build_latest + steps: + - name: executing remote ssh commands using password + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.TARGET_HOST }} + username: ${{ secrets.TARGET_HOST_USERNAME }} + password: ${{ secrets.TARGET_HOST_PASSWORD }} + port: ${{ secrets.TARGET_HOST_SSH_PORT }} + script: | + docker pull ppcelery/one-api:latest + cd /home/laisky/repo/VPS + docker-compose -f b1-docker-compose.yml up -d --remove-orphans --force-recreate oneapi + docker ps + + build_arm64_hash: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Add SHORT_SHA env property with commit short sha + run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c1-7`" >> $GITHUB_ENV + + - name: Build and push arm64 hash label + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ppcelery/one-api:arm64-${{ env.SHORT_SHA }} + platforms: linux/arm64 + cache-from: type=gha + cache-to: type=gha,mode=max + + build_arm64_latest: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Build and push arm64 latest + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ppcelery/one-api:arm64-latest + platforms: linux/arm64 + cache-from: type=gha + # cache-to: type=gha,mode=max diff --git a/.github/workflows/docker-image-en.yml b/.github/workflows/docker-image-en.yml deleted file mode 100644 index 30cd0e38..00000000 --- a/.github/workflows/docker-image-en.yml +++ /dev/null @@ -1,64 +0,0 @@ -name: Publish Docker image (English) - -on: - push: - tags: - - 'v*.*.*' - workflow_dispatch: - inputs: - name: - description: 'reason' - required: false -jobs: - push_to_registries: - name: Push Docker image to multiple registries - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Check repository URL - run: | - REPO_URL=$(git config --get remote.origin.url) - if [[ $REPO_URL == *"pro" ]]; then - exit 1 - fi - - - name: Save version info - run: | - git describe --tags > VERSION - - - name: Translate - run: | - python ./i18n/translate.py --repository_path . --json_file_path ./i18n/en.json - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: | - justsong/one-api-en - - - name: Build and push Docker images - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml deleted file mode 100644 index 56f1d6ad..00000000 --- a/.github/workflows/docker-image.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Publish Docker image - -on: - push: - tags: - - 'v*.*.*' - workflow_dispatch: - inputs: - name: - description: 'reason' - required: false -jobs: - push_to_registries: - name: Push Docker image to multiple registries - runs-on: ubuntu-latest - permissions: - packages: write - contents: read - steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Check repository URL - run: | - REPO_URL=$(git config --get remote.origin.url) - if [[ $REPO_URL == *"pro" ]]; then - exit 1 - fi - - - name: Save version info - run: | - git describe --tags > VERSION - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Docker Hub - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_TOKEN }} - - - name: Log in to the Container registry - uses: docker/login-action@v2 - with: - registry: ghcr.io - username: ${{ github.actor }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: | - justsong/one-api - ghcr.io/${{ github.repository }} - - - name: Build and push Docker images - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64,linux/arm64 - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 00000000..460fe33d --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,53 @@ +name: lint + +on: + push: + branches: + - "master" + - "main" + - "test/ci" + +jobs: + unit_tests: + name: "Unit tests" + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: ^1.23 + + - name: Install ffmpeg + run: sudo apt-get update && sudo apt-get install -y ffmpeg + + # When you execute your unit tests, make sure to use the "-coverprofile" flag to write a + # coverage profile to a file. You will need the name of the file (e.g. "coverage.txt") + # in the next step as well as the next job. + - name: Test + run: go test -cover -coverprofile=coverage.txt ./... + + - name: Archive code coverage results + uses: actions/upload-artifact@v4 + with: + name: code-coverage + path: coverage.txt # Make sure to use the same file name you chose for the "-coverprofile" in the "Test" step + + code_coverage: + name: "Code coverage report" + if: github.event_name == 'pull_request' # Do not run when workflow is triggered by push to main branch + runs-on: ubuntu-latest + needs: unit_tests # Depends on the artifact uploaded by the "unit_tests" job + steps: + - uses: fgrosse/go-coverage-report@v1.0.2 # Consider using a Git revision for maximum security + with: + coverage-artifact-name: "code-coverage" # can be omitted if you used this default value + coverage-file-name: "coverage.txt" # can be omitted if you used this default value + + commit_lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: wagoid/commitlint-github-action@v6 diff --git a/.github/workflows/linux-release.yml b/.github/workflows/linux-release.yml index 161c41e3..5e12fc9f 100644 --- a/.github/workflows/linux-release.yml +++ b/.github/workflows/linux-release.yml @@ -62,4 +62,4 @@ jobs: draft: true generate_release_notes: true env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 00000000..5c7617d4 --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,35 @@ +name: pr-check + +on: + pull_request: + branches: + - "master" + - "main" + +jobs: + build_latest: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to Docker Hub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: try to build + uses: docker/build-push-action@v5 + with: + context: . + push: false + tags: ppcelery/one-api:pr + cache-from: type=gha + cache-to: type=gha,mode=max diff --git a/.github/workflows/windows-release.yml b/.github/workflows/windows-release.yml index 18641ae8..939efd8d 100644 --- a/.github/workflows/windows-release.yml +++ b/.github/workflows/windows-release.yml @@ -56,4 +56,4 @@ jobs: draft: true generate_release_notes: true env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore index 4e431e65..e7f1e0a2 100644 --- a/.gitignore +++ b/.gitignore @@ -7,6 +7,8 @@ build *.db-journal logs data +node_modules /web/node_modules cmd.md -.env \ No newline at end of file +.env +/one-api diff --git a/Dockerfile b/Dockerfile index 0f00d092..052547ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM --platform=$BUILDPLATFORM node:16 AS builder +FROM node:18 as builder WORKDIR /web COPY ./VERSION . @@ -16,9 +16,12 @@ WORKDIR /web/air RUN npm install RUN DISABLE_ESLINT_PLUGIN='true' REACT_APP_VERSION=$(cat ../VERSION) npm run build -FROM golang:alpine AS builder2 +FROM golang:1.23.3-bullseye AS builder2 -RUN apk add --no-cache g++ +RUN apt-get update +RUN apt-get install -y --no-install-recommends g++ make gcc git build-essential ca-certificates \ + && update-ca-certificates 2>/dev/null || true \ + && rm -rf /var/lib/apt/lists/* ENV GO111MODULE=on \ CGO_ENABLED=1 \ @@ -31,14 +34,14 @@ COPY . . COPY --from=builder /web/build ./web/build RUN go build -trimpath -ldflags "-s -w -X 'github.com/songquanpeng/one-api/common.Version=$(cat VERSION)' -extldflags '-static'" -o one-api -FROM alpine +FROM debian:bullseye -RUN apk update \ - && apk upgrade \ - && apk add --no-cache ca-certificates tzdata \ - && update-ca-certificates 2>/dev/null || true +RUN apt-get update +RUN apt-get install -y --no-install-recommends ca-certificates haveged tzdata ffmpeg \ + && update-ca-certificates 2>/dev/null || true \ + && rm -rf /var/lib/apt/lists/* COPY --from=builder2 /build/one-api / EXPOSE 3000 WORKDIR /data -ENTRYPOINT ["/one-api"] \ No newline at end of file +ENTRYPOINT ["/one-api"] diff --git a/README.md b/README.md index 5f9947b0..638e0f25 100644 --- a/README.md +++ b/README.md @@ -1,463 +1,117 @@ -
- - - - -
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 部署教程 - · - 使用方法 - · - 意见反馈 - · - 截图展示 - · - 在线演示 - · - 常见问题 - · - 相关项目 - · - 赞赏支持 -
+## Menu -> [!NOTE] -> 本项目为开源项目,使用者必须在遵循 OpenAI 的[使用条款](https://openai.com/policies/terms-of-use)以及**法律法规**的情况下使用,不得用于非法用途。 -> -> 根据[《生成式人工智能服务管理暂行办法》](http://www.cac.gov.cn/2023-07/13/c_1690898327029107.htm)的要求,请勿对中国地区公众提供一切未经备案的生成式人工智能服务。 +- [One API](#one-api) + - [Menu](#menu) + - [New Features](#new-features) + - [(Merged) Support gpt-vision](#merged-support-gpt-vision) + - [Support update user's remained quota](#support-update-users-remained-quota) + - [(Merged) Support aws claude](#merged-support-aws-claude) + - [Support openai images edits](#support-openai-images-edits) + - [Support gemini-2.0-flash-exp](#support-gemini-20-flash-exp) + - [Support replicate flux \& remix](#support-replicate-flux--remix) + - [Support replicate chat models](#support-replicate-chat-models) + - [Support OpenAI O1/O1-mini/O1-preview](#support-openai-o1o1-minio1-preview) + - [Get request's cost](#get-requests-cost) + - [Support Vertex Imagen3](#support-vertex-imagen3) + - [Support gpt-4o-audio](#support-gpt-4o-audio) + - [Bug fix](#bug-fix) + - [The token balance cannot be edited](#the-token-balance-cannot-be-edited) + - [Whisper's transcription only charges for the length of the input audio](#whispers-transcription-only-charges-for-the-length-of-the-input-audio) -> [!WARNING] -> 使用 Docker 拉取的最新镜像可能是 `alpha` 版本,如果追求稳定性请手动指定版本。 +## New Features -> [!WARNING] -> 使用 root 用户初次登录系统后,务必修改默认密码 `123456`! +### (Merged) Support gpt-vision -## 功能 -1. 支持多种大模型: - + [x] [OpenAI ChatGPT 系列模型](https://platform.openai.com/docs/guides/gpt/chat-completions-api)(支持 [Azure OpenAI API](https://learn.microsoft.com/en-us/azure/ai-services/openai/reference)) - + [x] [Anthropic Claude 系列模型](https://anthropic.com) (支持 AWS Claude) - + [x] [Google PaLM2/Gemini 系列模型](https://developers.generativeai.google) - + [x] [Mistral 系列模型](https://mistral.ai/) - + [x] [字节跳动豆包大模型](https://console.volcengine.com/ark/region:ark+cn-beijing/model) - + [x] [百度文心一言系列模型](https://cloud.baidu.com/doc/WENXINWORKSHOP/index.html) - + [x] [阿里通义千问系列模型](https://help.aliyun.com/document_detail/2400395.html) - + [x] [讯飞星火认知大模型](https://www.xfyun.cn/doc/spark/Web.html) - + [x] [智谱 ChatGLM 系列模型](https://bigmodel.cn) - + [x] [360 智脑](https://ai.360.cn) - + [x] [腾讯混元大模型](https://cloud.tencent.com/document/product/1729) - + [x] [Moonshot AI](https://platform.moonshot.cn/) - + [x] [百川大模型](https://platform.baichuan-ai.com) - + [x] [MINIMAX](https://api.minimax.chat/) - + [x] [Groq](https://wow.groq.com/) - + [x] [Ollama](https://github.com/ollama/ollama) - + [x] [零一万物](https://platform.lingyiwanwu.com/) - + [x] [阶跃星辰](https://platform.stepfun.com/) - + [x] [Coze](https://www.coze.com/) - + [x] [Cohere](https://cohere.com/) - + [x] [DeepSeek](https://www.deepseek.com/) - + [x] [Cloudflare Workers AI](https://developers.cloudflare.com/workers-ai/) - + [x] [DeepL](https://www.deepl.com/) - + [x] [together.ai](https://www.together.ai/) - + [x] [novita.ai](https://www.novita.ai/) - + [x] [硅基流动 SiliconCloud](https://siliconflow.cn/siliconcloud) -2. 支持配置镜像以及众多[第三方代理服务](https://iamazing.cn/page/openai-api-third-party-services)。 -3. 支持通过**负载均衡**的方式访问多个渠道。 -4. 支持 **stream 模式**,可以通过流式传输实现打字机效果。 -5. 支持**多机部署**,[详见此处](#多机部署)。 -6. 支持**令牌管理**,设置令牌的过期时间、额度、允许的 IP 范围以及允许的模型访问。 -7. 支持**兑换码管理**,支持批量生成和导出兑换码,可使用兑换码为账户进行充值。 -8. 支持**渠道管理**,批量创建渠道。 -9. 支持**用户分组**以及**渠道分组**,支持为不同分组设置不同的倍率。 -10. 支持渠道**设置模型列表**。 -11. 支持**查看额度明细**。 -12. 支持**用户邀请奖励**。 -13. 支持以美元为单位显示额度。 -14. 支持发布公告,设置充值链接,设置新用户初始额度。 -15. 支持模型映射,重定向用户的请求模型,如无必要请不要设置,设置之后会导致请求体被重新构造而非直接透传,会导致部分还未正式支持的字段无法传递成功。 -16. 支持失败自动重试。 -17. 支持绘图接口。 -18. 支持 [Cloudflare AI Gateway](https://developers.cloudflare.com/ai-gateway/providers/openai/),渠道设置的代理部分填写 `https://gateway.ai.cloudflare.com/v1/ACCOUNT_TAG/GATEWAY/openai` 即可。 -19. 支持丰富的**自定义**设置, - 1. 支持自定义系统名称,logo 以及页脚。 - 2. 支持自定义首页和关于页面,可以选择使用 HTML & Markdown 代码进行自定义,或者使用一个单独的网页通过 iframe 嵌入。 -20. 支持通过系统访问令牌调用管理 API,进而**在无需二开的情况下扩展和自定义** One API 的功能,详情请参考此处 [API 文档](./docs/API.md)。。 -21. 支持 Cloudflare Turnstile 用户校验。 -22. 支持用户管理,支持**多种用户登录注册方式**: - + 邮箱登录注册(支持注册邮箱白名单)以及通过邮箱进行密码重置。 - + 支持使用飞书进行授权登录。 - + [GitHub 开放授权](https://github.com/settings/applications/new)。 - + 微信公众号授权(需要额外部署 [WeChat Server](https://github.com/songquanpeng/wechat-server))。 -23. 支持主题切换,设置环境变量 `THEME` 即可,默认为 `default`,欢迎 PR 更多主题,具体参考[此处](./web/README.md)。 -24. 配合 [Message Pusher](https://github.com/songquanpeng/message-pusher) 可将报警信息推送到多种 App 上。 +### Support update user's remained quota -## 部署 -### 基于 Docker 进行部署 -```shell -# 使用 SQLite 的部署命令: -docker run --name one-api -d --restart always -p 3000:3000 -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api -# 使用 MySQL 的部署命令,在上面的基础上添加 `-e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi"`,请自行修改数据库连接参数,不清楚如何修改请参见下面环境变量一节。 -# 例如: -docker run --name one-api -d --restart always -p 3000:3000 -e SQL_DSN="root:123456@tcp(localhost:3306)/oneapi" -e TZ=Asia/Shanghai -v /home/ubuntu/data/one-api:/data justsong/one-api -``` +You can update the used quota using the API key of any token, allowing other consumption to be aggregated into the one-api for centralized management. -其中,`-p 3000:3000` 中的第一个 `3000` 是宿主机的端口,可以根据需要进行修改。 + -数据和日志将会保存在宿主机的 `/home/ubuntu/data/one-api` 目录,请确保该目录存在且具有写入权限,或者更改为合适的目录。 +### (Merged) Support aws claude -如果启动失败,请添加 `--privileged=true`,具体参考 https://github.com/songquanpeng/one-api/issues/482 。 +- [feat: support aws bedrockruntime claude3 #1328](https://github.com/songquanpeng/one-api/pull/1328) +- [feat: add new claude models #1910](https://github.com/songquanpeng/one-api/pull/1910) -如果上面的镜像无法拉取,可以尝试使用 GitHub 的 Docker 镜像,将上面的 `justsong/one-api` 替换为 `ghcr.io/songquanpeng/one-api` 即可。 + -如果你的并发量较大,**务必**设置 `SQL_DSN`,详见下面[环境变量](#环境变量)一节。 +### Support openai images edits -更新命令:`docker run --rm -v /var/run/docker.sock:/var/run/docker.sock containrrr/watchtower -cR` +- [feat: support openai images edits api #1369](https://github.com/songquanpeng/one-api/pull/1369) -Nginx 的参考配置: -``` -server{ - server_name openai.justsong.cn; # 请根据实际情况修改你的域名 + - location / { - client_max_body_size 64m; - proxy_http_version 1.1; - proxy_pass http://localhost:3000; # 请根据实际情况修改你的端口 - proxy_set_header Host $host; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_cache_bypass $http_upgrade; - proxy_set_header Accept-Encoding gzip; - proxy_read_timeout 300s; # GPT-4 需要较长的超时时间,请自行调整 - } +### Support gemini-2.0-flash-exp + +- [feat: add gemini-2.0-flash-exp #1983](https://github.com/songquanpeng/one-api/pull/1983) + + + +### Support replicate flux & remix + +- [feature: 支持 replicate 的绘图 #1954](https://github.com/songquanpeng/one-api/pull/1954) +- [feat: image edits/inpaiting 支持 replicate 的 flux remix #1986](https://github.com/songquanpeng/one-api/pull/1986) + + + + + + + +### Support replicate chat models + +- [feat: 支持 replicate chat models #1989](https://github.com/songquanpeng/one-api/pull/1989) + +### Support OpenAI O1/O1-mini/O1-preview + +- [feat: add openai o1 #1990](https://github.com/songquanpeng/one-api/pull/1990) + +### Get request's cost + +Each chat completion request will include a `X-Oneapi-Request-Id` in the returned headers. You can use this request id to request `GET /api/cost/request/:request_id` to get the cost of this request. + +The returned structure is: + +```go +type UserRequestCost struct { + Id int `json:"id"` + CreatedTime int64 `json:"created_time" gorm:"bigint"` + UserID int `json:"user_id"` + RequestID string `json:"request_id"` + Quota int64 `json:"quota"` + CostUSD float64 `json:"cost_usd" gorm:"-"` } ``` -之后使用 Let's Encrypt 的 certbot 配置 HTTPS: -```bash -# Ubuntu 安装 certbot: -sudo snap install --classic certbot -sudo ln -s /snap/bin/certbot /usr/bin/certbot -# 生成证书 & 修改 Nginx 配置 -sudo certbot --nginx -# 根据指示进行操作 -# 重启 Nginx -sudo service nginx restart -``` +### Support Vertex Imagen3 -初始账号用户名为 `root`,密码为 `123456`。 +- [feat: support vertex imagen3 #2030](https://github.com/songquanpeng/one-api/pull/2030) + -### 基于 Docker Compose 进行部署 +### Support gpt-4o-audio -> 仅启动方式不同,参数设置不变,请参考基于 Docker 部署部分 +- [feat: support gpt-4o-audio #2032](https://github.com/songquanpeng/one-api/pull/2032) -```shell -# 目前支持 MySQL 启动,数据存储在 ./data/mysql 文件夹内 -docker-compose up -d + -# 查看部署状态 -docker-compose ps -``` + -### 手动部署 -1. 从 [GitHub Releases](https://github.com/songquanpeng/one-api/releases/latest) 下载可执行文件或者从源码编译: - ```shell - git clone https://github.com/songquanpeng/one-api.git +## Bug fix - # 构建前端 - cd one-api/web/default - npm install - npm run build +### The token balance cannot be edited - # 构建后端 - cd ../.. - go mod download - go build -ldflags "-s -w" -o one-api - ```` -2. 运行: - ```shell - chmod u+x one-api - ./one-api --port 3000 --log-dir ./logs - ``` -3. 访问 [http://localhost:3000/](http://localhost:3000/) 并登录。初始账号用户名为 `root`,密码为 `123456`。 +- [BUGFIX: 更新令牌时的一些问题 #1933](https://github.com/songquanpeng/one-api/pull/1933) -更加详细的部署教程[参见此处](https://iamazing.cn/page/how-to-deploy-a-website)。 +### Whisper's transcription only charges for the length of the input audio -### 多机部署 -1. 所有服务器 `SESSION_SECRET` 设置一样的值。 -2. 必须设置 `SQL_DSN`,使用 MySQL 数据库而非 SQLite,所有服务器连接同一个数据库。 -3. 所有从服务器必须设置 `NODE_TYPE` 为 `slave`,不设置则默认为主服务器。 -4. 设置 `SYNC_FREQUENCY` 后服务器将定期从数据库同步配置,在使用远程数据库的情况下,推荐设置该项并启用 Redis,无论主从。 -5. 从服务器可以选择设置 `FRONTEND_BASE_URL`,以重定向页面请求到主服务器。 -6. 从服务器上**分别**装好 Redis,设置好 `REDIS_CONN_STRING`,这样可以做到在缓存未过期的情况下数据库零访问,可以减少延迟。 -7. 如果主服务器访问数据库延迟也比较高,则也需要启用 Redis,并设置 `SYNC_FREQUENCY`,以定期从数据库同步配置。 - -环境变量的具体使用方法详见[此处](#环境变量)。 - -### 宝塔部署教程 - -详见 [#175](https://github.com/songquanpeng/one-api/issues/175)。 - -如果部署后访问出现空白页面,详见 [#97](https://github.com/songquanpeng/one-api/issues/97)。 - -### 部署第三方服务配合 One API 使用 -> 欢迎 PR 添加更多示例。 - -#### ChatGPT Next Web -项目主页:https://github.com/Yidadaa/ChatGPT-Next-Web - -```bash -docker run --name chat-next-web -d -p 3001:3000 yidadaa/chatgpt-next-web -``` - -注意修改端口号,之后在页面上设置接口地址(例如:https://openai.justsong.cn/ )和 API Key 即可。 - -#### ChatGPT Web -项目主页:https://github.com/Chanzhaoyu/chatgpt-web - -```bash -docker run --name chatgpt-web -d -p 3002:3002 -e OPENAI_API_BASE_URL=https://openai.justsong.cn -e OPENAI_API_KEY=sk-xxx chenzhaoyu94/chatgpt-web -``` - -注意修改端口号、`OPENAI_API_BASE_URL` 和 `OPENAI_API_KEY`。 - -#### QChatGPT - QQ机器人 -项目主页:https://github.com/RockChinQ/QChatGPT - -根据[文档](https://qchatgpt.rockchin.top)完成部署后,在 `data/provider.json`设置`requester.openai-chat-completions.base-url`为 One API 实例地址,并填写 API Key 到 `keys.openai` 组中,设置 `model` 为要使用的模型名称。 - -运行期间可以通过`!model`命令查看、切换可用模型。 - -### 部署到第三方平台 -