Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,34 @@ Sub2API is an AI API gateway platform designed to distribute and manage API quot
## Documentation

- Dependency Security: `docs/dependency-security.md`
- Admin Payment Integration API: `docs/ADMIN_PAYMENT_INTEGRATION_API.md`

---

## Codex CLI WebSocket v2 Example

To enable OpenAI WebSocket Mode v2 in Codex CLI with Sub2API, add the following to `~/.codex/config.toml`:

```toml
model_provider = "aicodx2api"
model = "gpt-5.3-codex"
review_model = "gpt-5.3-codex"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true

[model_providers.aicodx2api]
name = "aicodx2api"
base_url = "https://api.sub2api.ai"
wire_api = "responses"
supports_websockets = true
requires_openai_auth = true

[features]
responses_websockets_v2 = true
```

After updating the config, restart Codex CLI.

---

Expand Down
28 changes: 28 additions & 0 deletions README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ Sub2API 是一个 AI API 网关平台,用于分发和管理 AI 产品订阅(
- 当请求包含 `function_call_output` 时,需要携带 `previous_response_id`,或在 `input` 中包含带 `call_id` 的 `tool_call`/`function_call`,或带非空 `id` 且与 `function_call_output.call_id` 匹配的 `item_reference`。
- 若依赖上游历史记录,网关会强制 `store=true` 并需要复用 `previous_response_id`,以避免出现 “No tool call found for function call output” 错误。

## Codex CLI 开启 OpenAI WebSocket Mode v2 示例配置

如需在 Codex CLI 中通过 Sub2API 启用 OpenAI WebSocket Mode v2,可将以下配置写入 `~/.codex/config.toml`:

```toml
model_provider = "aicodx2api"
model = "gpt-5.3-codex"
review_model = "gpt-5.3-codex"
model_reasoning_effort = "xhigh"
disable_response_storage = true
network_access = "enabled"
windows_wsl_setup_acknowledged = true

[model_providers.aicodx2api]
name = "aicodx2api"
base_url = "https://api.sub2api.ai"
wire_api = "responses"
supports_websockets = true
requires_openai_auth = true

[features]
responses_websockets_v2 = true
```

配置更新后,重启 Codex CLI 使其生效。

---

## 部署方式

### 方式一:脚本安装(推荐)
Expand Down
17 changes: 0 additions & 17 deletions backend/.golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ linters:
enable:
- depguard
- errcheck
- gosec
- govet
- ineffassign
- staticcheck
Expand Down Expand Up @@ -43,22 +42,6 @@ linters:
desc: "handler must not import gorm"
- pkg: github.com/redis/go-redis/v9
desc: "handler must not import redis"
gosec:
excludes:
- G101
- G103
- G104
- G109
- G115
- G201
- G202
- G301
- G302
- G304
- G306
- G404
severity: high
confidence: high
errcheck:
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
# Such cases aren't reported by default.
Expand Down
5 changes: 5 additions & 0 deletions backend/.gosec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"global": {
"exclude": "G704,G101,G103,G104,G109,G115,G201,G202,G301,G302,G304,G306,G404"
}
}
2 changes: 1 addition & 1 deletion backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.25.7-alpine
FROM registry-1.docker.io/library/golang:1.25.7-alpine

WORKDIR /app

Expand Down
26 changes: 26 additions & 0 deletions backend/THIRD_PARTY_NOTICES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Third-Party Notices

## caddyserver/caddy

- Project: https://github.com/caddyserver/caddy
- License: Apache License 2.0
- Copyright:
Copyright 2015 Matthew Holt and The Caddy Authors

### Usage in this repository

OpenAI WS v2 passthrough relay adopts the Caddy reverse proxy streaming architecture
(bidirectional tunnel + convergence shutdown) and is adapted with minimal changes for
`coder/websocket` frame-based forwarding.

- Referenced commit:
`f283062d37c50627d53ca682ebae2ce219b35515`
- Referenced upstream files:
- `modules/caddyhttp/reverseproxy/streaming.go`
- `modules/caddyhttp/reverseproxy/reverseproxy.go`
- Local adaptation files:
- `backend/internal/service/openai_ws_v2/caddy_adapter.go`
- `backend/internal/service/openai_ws_v2/passthrough_relay.go`

The adaptation preserves Apache-2.0 license obligations.

2 changes: 1 addition & 1 deletion backend/cmd/jwtgen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func main() {
}()

userRepo := repository.NewUserRepository(client, sqlDB)
authService := service.NewAuthService(userRepo, nil, nil, cfg, nil, nil, nil, nil, nil, nil)
authService := service.NewAuthService(userRepo, nil, nil, cfg, nil, nil, nil, nil, nil)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
Expand Down
2 changes: 1 addition & 1 deletion backend/cmd/server/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.88
0.1.87.4
4 changes: 2 additions & 2 deletions backend/cmd/server/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,9 @@ func provideCleanup(
antigravityOAuth.Stop()
return nil
}},
{"OpenAIWSPool", func() error {
{"OpenAIWSCtxPool", func() error {
if openAIGateway != nil {
openAIGateway.CloseOpenAIWSPool()
openAIGateway.CloseOpenAIWSCtxPool()
}
return nil
}},
Expand Down
24 changes: 10 additions & 14 deletions backend/cmd/server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ require (
github.com/goccy/go-json v0.10.2 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/google/subcommands v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.3 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/hcl/v2 v2.18.1 // indirect
Expand Down Expand Up @@ -178,7 +177,6 @@ require (
golang.org/x/mod v0.32.0 // indirect
golang.org/x/sys v0.41.0 // indirect
golang.org/x/text v0.34.0 // indirect
golang.org/x/tools v0.41.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250929231259-57b25ae835d4 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
modernc.org/libc v1.67.6 // indirect
Expand Down
2 changes: 0 additions & 2 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e h1:ijClszYn+mADRFY17kjQEVQ1XRhq2/JR1M3sGqeJoxs=
github.com/google/pprof v0.0.0-20250317173921-a4b03ec1a45e/go.mod h1:boTsfXsheKC2y+lKOCMpSfarhxDeIzfZG1jqGcPl3cA=
github.com/google/subcommands v1.2.0 h1:vWQspBTo2nEqTUFita5/KeEWlUL8kQObDFbub/EN9oE=
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/google/wire v0.7.0 h1:JxUKI6+CVBgCO2WToKy/nQk0sS+amI9z9EjVmdaocj4=
Expand Down
Loading
Loading