claude-codex-proxy 1.0.5-beta.17 → 1.0.5-beta.19

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.17",
3
+ "version": "1.0.5-beta.19",
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",
package/public/js/app.js CHANGED
@@ -117,7 +117,32 @@ document.addEventListener('alpine:init', () => {
117
117
  async loadRateLimitResetCredits(email) { this.resetCreditsLoading = true; this.resetCredits = []; this.resetCreditsAccountEmail = email; this.resetCreditRedeemRequestId = ''; const { ok, data } = await this.api(`/accounts/rate-limit-reset-credits?email=${encodeURIComponent(email)}`); this.resetCreditsLoading = false; if (this.resetCreditsAccountEmail !== email) return; if (ok) this.resetCredits = this.normalizeRateLimitResetCredits(data?.credits); else this.showToast(data?.error || 'Failed to load reset credits', 'error'); },
118
118
  availableRateLimitResetCredits() { return this.resetCredits.filter(credit => credit?.status === 'available').sort((a, b) => new Date(b.expires_at || 0).getTime() - new Date(a.expires_at || 0).getTime()); },
119
119
  resetCreditExpiryLabel(credit) { const date = credit?.expires_at && new Date(credit.expires_at); return date && !Number.isNaN(date.getTime()) ? date.toLocaleString() : '-'; },
120
- async redeemRateLimitResetCredit(creditId = null) { if (!this.selectedAccount || this.resetCreditsRedeeming) return; this.resetCreditsRedeeming = true; if (!this.resetCreditRedeemRequestId) this.resetCreditRedeemRequestId = crypto.randomUUID(); const { ok, data } = await this.api('/accounts/rate-limit-reset-credits/consume', { method: 'POST', body: JSON.stringify({ email: this.selectedAccount.email, creditId: creditId || undefined, redeemRequestId: this.resetCreditRedeemRequestId }) }); this.resetCreditsRedeeming = false; if (ok && data?.success) { this.showToast('Quota reset credit redeemed', 'success'); this.resetCreditRedeemRequestId = ''; await Promise.all([this.loadRateLimitResetCredits(this.selectedAccount.email), this.refreshAccounts()]); } else this.showToast(data?.error || 'Failed to redeem reset credit', 'error'); },
120
+ generateUUID() {
121
+ if (typeof globalThis.crypto?.randomUUID === 'function') {
122
+ return globalThis.crypto.randomUUID();
123
+ }
124
+
125
+ const bytes = new Uint8Array(16);
126
+ globalThis.crypto.getRandomValues(bytes);
127
+
128
+ // UUID v4
129
+ bytes[6] = (bytes[6] & 0x0f) | 0x40;
130
+ bytes[8] = (bytes[8] & 0x3f) | 0x80;
131
+
132
+ const hex = Array.from(
133
+ bytes,
134
+ byte => byte.toString(16).padStart(2, '0')
135
+ );
136
+
137
+ return [
138
+ hex.slice(0, 4).join(''),
139
+ hex.slice(4, 6).join(''),
140
+ hex.slice(6, 8).join(''),
141
+ hex.slice(8, 10).join(''),
142
+ hex.slice(10, 16).join('')
143
+ ].join('-');
144
+ },
145
+ async redeemRateLimitResetCredit(creditId = null) { if (!this.selectedAccount || this.resetCreditsRedeeming) return; this.resetCreditsRedeeming = true; if (!this.resetCreditRedeemRequestId) this.resetCreditRedeemRequestId = this.generateUUID(); const { ok, data } = await this.api('/accounts/rate-limit-reset-credits/consume', { method: 'POST', body: JSON.stringify({ email: this.selectedAccount.email, creditId: creditId || undefined, redeemRequestId: this.resetCreditRedeemRequestId }) }); this.resetCreditsRedeeming = false; if (ok && data?.success) { this.showToast('Quota reset credit redeemed', 'success'); this.resetCreditRedeemRequestId = ''; await Promise.all([this.loadRateLimitResetCredits(this.selectedAccount.email), this.refreshAccounts()]); } else this.showToast(data?.error || 'Failed to redeem reset credit', 'error'); },
121
146
  async testChat() { if (!this.testPrompt.trim()) return; this.testing = true; this.testResponse = ''; const { ok, data } = await this.api('/v1/chat/completions', { method: 'POST', body: JSON.stringify({ model: this.modelMappings?.sonnet || 'gpt-5.5', messages: [{ role: 'user', content: this.testPrompt }] }) }); this.testing = false; this.testResponse = ok && data.choices ? data.choices[0]?.message?.content || `[Empty response]\n\n${JSON.stringify(data, null, 2)}` : data?.error?.message || data?.error || 'Request failed'; },
122
147
  async loadAccountStrategySetting() { const { ok, data } = await this.api('/settings/account-strategy'); if (ok && data?.accountStrategy) this.accountStrategy = data.accountStrategy; }, async setAccountStrategy(strategy) { if (this.strategySaving || this.accountStrategy === strategy) return; this.strategySaving = true; const { ok, data } = await this.api('/settings/account-strategy', { method: 'POST', body: JSON.stringify({ accountStrategy: strategy }) }); this.strategySaving = false; if (ok && data?.accountStrategy) this.accountStrategy = data.accountStrategy; else this.showToast(data?.error || 'Failed to update strategy', 'error'); },
123
148
  async loadRawProxyLogsSetting() { const { ok, data } = await this.api('/settings/raw-proxy-logs'); if (ok && typeof data?.logRawProxyPayloads === 'boolean') this.logRawProxyPayloads = data.logRawProxyPayloads; }, async setRawProxyLogs(enabled) { if (this.rawProxyLogsSaving || this.logRawProxyPayloads === enabled) return; this.rawProxyLogsSaving = true; const { ok, data } = await this.api('/settings/raw-proxy-logs', { method: 'POST', body: JSON.stringify({ enabled }) }); this.rawProxyLogsSaving = false; if (ok && typeof data?.logRawProxyPayloads === 'boolean') this.logRawProxyPayloads = data.logRawProxyPayloads; else this.showToast(data?.error || 'Failed to update raw proxy logging', 'error'); },
@@ -5,6 +5,8 @@
5
5
 
6
6
  export const PRICE_UNIT_TOKENS = 1_000_000;
7
7
  export const LONG_CONTEXT_THRESHOLD_TOKENS = 272_000;
8
+ // For models without a configured price, billing is uniformly based on this model.
9
+ export const DEFAULT_PRICING_MODEL = 'gpt-5.6-sol';
8
10
 
9
11
  const STANDARD_PRICING = {
10
12
  'gpt-5.6-sol': {
@@ -44,20 +46,46 @@ const LONG_CONTEXT_PRICING = {
44
46
 
45
47
  /**
46
48
  * Returns the applicable USD-per-million-token price record for an upstream
47
- * model. Models without a configured price return null.
49
+ * model. Models without a configured price use DEFAULT_PRICING_MODEL.
48
50
  */
49
51
  export function getModelPricing(model, inputTokens = 0) {
50
- const normalizedModel = String(model || '').toLowerCase();
51
- const standard = STANDARD_PRICING[normalizedModel];
52
- if (!standard) return null;
52
+ const requestedModel = String(model || '').trim().toLowerCase();
53
53
 
54
- const usesLongContext = Number(inputTokens) > LONG_CONTEXT_THRESHOLD_TOKENS;
55
- const longContext = usesLongContext ? LONG_CONTEXT_PRICING[normalizedModel] : null;
54
+ // Use the current model if it has a price;
55
+ // use the default pricing model if no price is configured.
56
+ const pricingModel = STANDARD_PRICING[requestedModel]
57
+ ? requestedModel
58
+ : DEFAULT_PRICING_MODEL;
59
+
60
+ const standard = STANDARD_PRICING[pricingModel];
61
+
62
+ // Prevent DEFAULT_PRICING_MODEL configuration errors.
63
+ if (!standard) {
64
+ throw new Error(
65
+ `Default pricing model "${DEFAULT_PRICING_MODEL}" is not configured`
66
+ );
67
+ }
68
+
69
+ const usesLongContext =
70
+ Number(inputTokens) > LONG_CONTEXT_THRESHOLD_TOKENS;
71
+
72
+ const longContext = usesLongContext
73
+ ? LONG_CONTEXT_PRICING[pricingModel]
74
+ : null;
56
75
 
57
76
  return {
58
77
  ...standard,
59
78
  ...(longContext || {}),
60
- model: normalizedModel,
79
+
80
+ // The model actually requested
81
+ model: requestedModel,
82
+
83
+ // The model actually used to calculate the price
84
+ pricingModel,
85
+
86
+ // Was the default price used?
87
+ fallbackPricing: requestedModel !== pricingModel,
88
+
61
89
  priceUnitTokens: PRICE_UNIT_TOKENS,
62
90
  longContext: Boolean(longContext)
63
91
  };
@@ -78,7 +106,6 @@ export function calculateUsageCostMicrousd(model, usage = {}) {
78
106
  );
79
107
  const cacheWriteTokens = Math.max(0, Number(usage.input_tokens_details?.cache_write_tokens) || 0);
80
108
  const pricing = getModelPricing(model, inputTokens);
81
- if (!pricing) return null;
82
109
 
83
110
  const uncachedInputTokens = Math.max(0, inputTokens - cachedInputTokens - cacheWriteTokens);
84
111
  const usd = (
@@ -93,4 +120,8 @@ export function calculateUsageCostMicrousd(model, usage = {}) {
93
120
 
94
121
  export { STANDARD_PRICING, LONG_CONTEXT_PRICING };
95
122
 
96
- export default { getModelPricing, calculateUsageCostMicrousd };
123
+ export default {
124
+ getModelPricing,
125
+ calculateUsageCostMicrousd,
126
+ DEFAULT_PRICING_MODEL
127
+ };