Subscription proxy adapters + worker correlation: record ChatGPT Pro/Codex and GLM Coding Plan token I/O #87

Open
opened 2026-09-19 05:30:22 +00:00 by nsaspy · 0 comments
Owner

Parent: #94
Related: #95
Consumer: starintel-labs/starintel-biz#124 #120 #113

Goal

Make llm-log a first-class proxy/recorder for subscription-backed coding providers as well as normal API providers.

Initial subscription routes:

  • ChatGPT Plus/Pro -> Codex backend
  • Z.AI GLM Coding Plan -> coding-plan API
  • future subscription-backed provider adapters

GLM Coding Plan

Support the official coding endpoint as a named upstream:
https://api.z.ai/api/coding/paas/v4.

Preserve the OpenAI-compatible chat/completions semantics and provider-reported usage fields.

ChatGPT Plus/Pro / Codex

Support the ChatGPT subscription OAuth/Codex request path without converting the subscription credential into a Platform API-key flow.

The proxy adapter must preserve the protocol semantics expected by the Codex backend, including required account/residency/provider headers, while redacting subscription OAuth credentials from capture.

The caller (including the Biz-owned OpenCode build) must be able to send the subscription request through llm-log instead of directly to the Codex endpoint.

Internal correlation headers

Reserve an llm-log-local metadata namespace, e.g.:

X-LLM-Log-Company
X-LLM-Log-Worker
X-LLM-Log-Agent
X-LLM-Log-Task
X-LLM-Log-Correlation-Id
X-LLM-Log-Causation-Id
X-LLM-Log-Plan

Rules:

  • capture/normalize these as request metadata;
  • strip them before upstream egress;
  • never let untrusted external clients spoof a more privileged tenant/principal;
  • service-authenticated internal callers may supply allowed attribution fields;
  • do not include secrets/prompt content in these headers.

Token/usage capture

Normalize provider-reported:

  • input tokens
  • output tokens
  • total tokens
  • cached input/read/write
  • reasoning tokens
  • provider quota/credit counters when exposed
  • request/model/provider IDs
  • rate-limit/reset headers when exposed

Record per upstream attempt and per logical request.

For subscription traffic, token I/O is operational accounting even where the marginal dollar charge is zero.

Attempt/fallback integration

When #95 sends an exhausted subscription/direct provider request to OpenRouter:

  • keep one logical request ID;
  • record each attempt independently;
  • retain subscription attempt/quota evidence;
  • retain OpenRouter token/cost evidence;
  • expose the final selected provider;
  • prevent double counting tokens/cost across attempts.

Privacy

  • redact OAuth/API credentials;
  • do not persist full auth JWTs;
  • no refresh token capture;
  • internal worker correlation metadata is allowed;
  • prompt/completion retention follows the configured privacy tier independently from usage telemetry.

Acceptance

  • GLM Coding Plan proxy fixture
  • ChatGPT Plus/Pro Codex proxy fixture
  • subscription credentials redacted
  • correlation headers captured then stripped upstream
  • input/output/total tokens normalized
  • cached/reasoning usage normalized when present
  • rate/quota/reset metadata normalized when present
  • multi-attempt logical request joins #95 fallback chain
  • worker/task correlation query works
  • streaming and non-streaming coverage
  • no subscription request silently bypasses capture when caller is configured for llm-log
Parent: #94 Related: #95 Consumer: starintel-labs/starintel-biz#124 #120 #113 ## Goal Make llm-log a first-class proxy/recorder for subscription-backed coding providers as well as normal API providers. Initial subscription routes: - ChatGPT Plus/Pro -> Codex backend - Z.AI GLM Coding Plan -> coding-plan API - future subscription-backed provider adapters ## GLM Coding Plan Support the official coding endpoint as a named upstream: `https://api.z.ai/api/coding/paas/v4`. Preserve the OpenAI-compatible chat/completions semantics and provider-reported usage fields. ## ChatGPT Plus/Pro / Codex Support the ChatGPT subscription OAuth/Codex request path without converting the subscription credential into a Platform API-key flow. The proxy adapter must preserve the protocol semantics expected by the Codex backend, including required account/residency/provider headers, while redacting subscription OAuth credentials from capture. The caller (including the Biz-owned OpenCode build) must be able to send the subscription request through llm-log instead of directly to the Codex endpoint. ## Internal correlation headers Reserve an llm-log-local metadata namespace, e.g.: ```text X-LLM-Log-Company X-LLM-Log-Worker X-LLM-Log-Agent X-LLM-Log-Task X-LLM-Log-Correlation-Id X-LLM-Log-Causation-Id X-LLM-Log-Plan ``` Rules: - capture/normalize these as request metadata; - strip them before upstream egress; - never let untrusted external clients spoof a more privileged tenant/principal; - service-authenticated internal callers may supply allowed attribution fields; - do not include secrets/prompt content in these headers. ## Token/usage capture Normalize provider-reported: - input tokens - output tokens - total tokens - cached input/read/write - reasoning tokens - provider quota/credit counters when exposed - request/model/provider IDs - rate-limit/reset headers when exposed Record per upstream attempt and per logical request. For subscription traffic, token I/O is operational accounting even where the marginal dollar charge is zero. ## Attempt/fallback integration When #95 sends an exhausted subscription/direct provider request to OpenRouter: - keep one logical request ID; - record each attempt independently; - retain subscription attempt/quota evidence; - retain OpenRouter token/cost evidence; - expose the final selected provider; - prevent double counting tokens/cost across attempts. ## Privacy - redact OAuth/API credentials; - do not persist full auth JWTs; - no refresh token capture; - internal worker correlation metadata is allowed; - prompt/completion retention follows the configured privacy tier independently from usage telemetry. ## Acceptance - [ ] GLM Coding Plan proxy fixture - [ ] ChatGPT Plus/Pro Codex proxy fixture - [ ] subscription credentials redacted - [ ] correlation headers captured then stripped upstream - [ ] input/output/total tokens normalized - [ ] cached/reasoning usage normalized when present - [ ] rate/quota/reset metadata normalized when present - [ ] multi-attempt logical request joins #95 fallback chain - [ ] worker/task correlation query works - [ ] streaming and non-streaming coverage - [ ] no subscription request silently bypasses capture when caller is configured for llm-log
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
nsaspy/llm-log#87
No description provided.