claude-codex-proxy 1.0.5-beta.24 → 1.0.5-beta.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-codex-proxy",
3
- "version": "1.0.5-beta.24",
3
+ "version": "1.0.5-beta.26",
4
4
  "description": "Multi-account proxy server for OpenAI Codex CLI with Claude API compatibility",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -56,19 +56,47 @@ export function handleStreamError(res, error, model, startTime) {
56
56
  const loggedModel = typeof model === 'string' && model.toLowerCase().startsWith('claude-')
57
57
  ? resolveModelRouting(model).upstreamModel
58
58
  : model;
59
- logger.response(status, { model: loggedModel, error: error.message, duration });
60
-
61
- if (res.headersSent) {
62
- res.write(
63
- `event: error\ndata: ${JSON.stringify({
64
- type: 'error',
65
- error: { type: errorType, message: getClientErrorMessage(error) }
66
- })}\n\n`
67
- );
68
- res.end();
59
+ const isStreamError = res.headersSent;
60
+ const logDetails = {
61
+ model: loggedModel,
62
+ transport: isStreamError ? 'sse' : 'http',
63
+ clientHttpStatus: isStreamError ? res.statusCode : status,
64
+ errorType,
65
+ retrySignal: errorType === 'overloaded_error',
66
+ errorName: error?.name,
67
+ errorCode: error?.code,
68
+ upstreamStatus: error?.upstreamStatus,
69
+ isUpstreamError: error?.isUpstreamError === true,
70
+ error: error?.message,
71
+ duration
72
+ };
73
+
74
+ if (isStreamError) {
75
+ const socketDestroyed = res.destroyed === true || res.socket?.destroyed === true;
76
+ const writableEnded = res.writableEnded === true;
77
+ const sseWriteAttempted = !socketDestroyed && !writableEnded;
78
+ let sseWriteBackpressure = false;
79
+ if (sseWriteAttempted) {
80
+ sseWriteBackpressure = !res.write(
81
+ `event: error\ndata: ${JSON.stringify({
82
+ type: 'error',
83
+ error: { type: errorType, message: getClientErrorMessage(error) }
84
+ })}\n\n`
85
+ );
86
+ res.end();
87
+ }
88
+ logger.response(status, {
89
+ ...logDetails,
90
+ sseWriteAttempted,
91
+ sseWriteBackpressure,
92
+ socketDestroyed,
93
+ writableEnded
94
+ });
69
95
  return;
70
96
  }
71
97
 
98
+ logger.response(status, logDetails);
99
+
72
100
  if (error.message.includes('AUTH_EXPIRED')) {
73
101
  return res.status(401).json({
74
102
  type: 'error',
@@ -115,6 +143,9 @@ function getErrorStatus(error) {
115
143
  }
116
144
 
117
145
  function getAnthropicErrorType(error, status) {
146
+ // Claude Code retries streamed overload errors by their Anthropic error type.
147
+ // HTTP status is already committed after SSE starts, so preserve 5xx semantics here.
148
+ if (status >= 500) return 'overloaded_error';
118
149
  if (error?.anthropicErrorType) return error.anthropicErrorType;
119
150
  if (status === 401) return 'authentication_error';
120
151
  if (status === 429) return 'rate_limit_error';
@@ -174,6 +174,18 @@ class Logger extends EventEmitter {
174
174
  if (details.inputTokens !== undefined) parts.push(`input_tokens=${details.inputTokens}`);
175
175
  if (details.outputTokens !== undefined) parts.push(`output_tokens=${details.outputTokens}`);
176
176
  if (details.cacheReadInputTokens !== undefined) parts.push(`cache_read_input_tokens=${details.cacheReadInputTokens}`);
177
+ if (details.transport) parts.push(`transport=${details.transport}`);
178
+ if (details.clientHttpStatus !== undefined) parts.push(`client_http_status=${details.clientHttpStatus}`);
179
+ if (details.errorType) parts.push(`error_type=${details.errorType}`);
180
+ if (details.retrySignal !== undefined) parts.push(`retry_signal=${details.retrySignal}`);
181
+ if (details.errorName) parts.push(`error_name=${details.errorName}`);
182
+ if (details.errorCode) parts.push(`error_code=${details.errorCode}`);
183
+ if (details.upstreamStatus !== undefined) parts.push(`upstream_status=${details.upstreamStatus}`);
184
+ if (details.isUpstreamError !== undefined) parts.push(`is_upstream_error=${details.isUpstreamError}`);
185
+ if (details.sseWriteAttempted !== undefined) parts.push(`sse_write_attempted=${details.sseWriteAttempted}`);
186
+ if (details.sseWriteBackpressure !== undefined) parts.push(`sse_write_backpressure=${details.sseWriteBackpressure}`);
187
+ if (details.socketDestroyed !== undefined) parts.push(`socket_destroyed=${details.socketDestroyed}`);
188
+ if (details.writableEnded !== undefined) parts.push(`writable_ended=${details.writableEnded}`);
177
189
  if (details.duration) parts.push(`${details.duration}ms`);
178
190
  if (details.error) parts.push(`error=${details.error}`);
179
191