Skip to content
Merged
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
6 changes: 6 additions & 0 deletions .jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,9 @@ In Express applications handling cross-origin traffic, placing the `cors()` midd

Action:
Moved the `cors()` middleware before `helmet()` in the global middleware stack. This allows `OPTIONS` preflight requests to be intercepted and resolved immediately by `cors`, bypassing unnecessary security header processing and improving baseline latency. Consolidated the `res.setHeader` calls in the JSON error handler into a single global setter.

## 2026-05-12 — Compression Middleware Overhead
Learning:
Global `compression()` middleware introduces significant CPU and memory allocation overhead on unhandled routes (404s) and lightweight responses.
Action:
Always apply `compression()` as a route-specific middleware only to endpoints that return large payloads.
6 changes: 6 additions & 0 deletions .jules/warden.md
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,9 @@ Observation / Pruned:
Assessed repository state following previous optimizations. Since no new functional or architectural changes were introduced by the prior agent run, no new release cut or version bump is warranted. Maintained semantic integrity by preserving the existing v1.1.31 state. Zero dead code identified and pruned.
Alignment / Deferred:
Release deferred. Repository state verified and stable.

2026-05-12 — Assessment & Lifecycle
Observation / Pruned:
Assessed BOLT's optimization converting `compression()` to a route-specific middleware. This prevents unhandled routes and simple endpoints from undergoing redundant compression overhead. Tests verified. Checked for unused dependencies and dead code. Zero dead code or unused files found.
Alignment / Deferred:
Appended release notes. Version bumped to 1.1.32.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.1.32] - 2026-05-12
### Changed
* **[Performance]:** Converted `compression()` from a global middleware to a route-specific middleware on the `/v1/chat/completions` endpoint. This prevents unhandled routes (404s) and lightweight responses from incurring unnecessary CPU overhead and memory allocation for compression.

## [1.1.31] - 2026-05-04
### Changed
* **[Performance]:** Moved the `cors()` middleware to be above `helmet()` in the global middleware stack. This allows `OPTIONS` preflight requests to be intercepted and resolved immediately by `cors`, bypassing unnecessary security header processing. Also, consolidated the `res.setHeader` calls in the JSON error handler.
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "one-api",
"version": "1.1.31",
"version": "1.1.32",
"description": "One API to rule them all. Unified gateway for 20+ LLM providers. OpenAI-compatible, single binary, zero config.",
"main": "src/index.js",
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ app.use((req, res, next) => {


// Compress all responses to reduce bandwidth and latency
app.use(compression());
const compressMiddleware = compression();

const ERROR_INVALID_JSON = Buffer.from(JSON.stringify({ error: 'Invalid JSON payload' }));
const ERROR_PAYLOAD_TOO_LARGE = Buffer.from(JSON.stringify({ error: 'Payload too large' }));
Expand Down Expand Up @@ -96,7 +96,7 @@ const ERROR_MALFORMED_MESSAGE = Buffer.from(JSON.stringify({ error: 'Malformed m
// Set a larger JSON limit since LLM contexts can be quite large
const jsonParser = express.json({ limit: '10mb' });

app.post('/v1/chat/completions', jsonParser, (req, res) => {
app.post('/v1/chat/completions', jsonParser, compressMiddleware, (req, res) => {
const body = req.body;
const model = body ? body.model : undefined;
const messages = body ? body.messages : undefined;
Expand Down
Loading