version: 1
kind: platform-infra-sub2api-codex-pool

metadata:
  id: sub2api-codex-pool
  owner: unidesk
  relatedIssues:
    - 339
    - 340

runtime:
  templates:
    - id: codex-upstream-failover
      kind: temp-unschedulable
      description: Reusable Sub2API request-path cooling and failover policy for Codex-compatible API-key accounts.
      spec:
        enabled: true
        rules:
          - statusCode: 502
            keywords: [upstream service temporarily unavailable, upstream request failed, context window, stream usage incomplete, missing terminal event]
            durationMinutes: 1
            description: Observed 502 upstream availability, context-window, and incomplete-stream failures briefly cool down the selected account.
          - statusCode: 503
            keywords: [upstream service temporarily unavailable, upstream request failed, temporarily unavailable]
            durationMinutes: 1
            description: Observed 503 temporary upstream availability failures briefly cool down the selected account.
          - statusCode: 524
            keywords: [upstream request failed, missing_required_parameter, encrypted_content]
            durationMinutes: 1
            description: Observed 524 upstream request and encrypted-content failures briefly cool down the selected account.

pool:
  groupName: unidesk-codex-pool
  groupDescription: UniDesk-managed Codex API-key pool for YAML-selected Sub2API clients.
  apiKeyName: unidesk-codex-pool-api-key
  apiKeySecretName: sub2api-codex-pool-api-key
  apiKeySecretKey: API_KEY
  adminEmailDefault: admin@sub2api.platform-infra.local
  minOwnerBalanceUsd: 1000
  defaultAccountPriority: 10
  defaultAccountCapacity: 10
  defaultAccountLoadFactor: 10
  defaultSentinelProtect:
    enabled: true
    consecutiveFailures: 3
    initialRetryDelaySeconds: 2
    maxRetryDelaySeconds: 60
    backoffMultiplier: 2
  defaultTempUnschedulableTemplate: codex-upstream-failover
profiles:
  entries:
    - profile: yjxm1221
      accountName: unidesk-codex-yjxm1221
      configFile: config.toml.yjxm1221
      authFile: auth.json.yjxm1221
      trustUpstream: true
      proxyId: 3
    - profile: yjxm1221-pro
      accountName: unidesk-codex-yjxm1221-pro
      configFile: config.toml.yjxm1221-pro
      authFile: auth.json.yjxm1221-pro
      priority: 50
      trustUpstream: true
      proxyId: 3
manualAccounts:
  bindingSources:
    active-target-egress-proxy:
      enabled: true
      kind: proxy
      provider: target-egress-proxy
      description: Bind a protected manual account to the selected target's YAML-declared egress proxy.
    pk01-host-proxy:
      enabled: true
      kind: proxy
      provider: fixed-http-proxy
      description: Bind protected/manual PK01 Sub2API accounts to the PK01 host proxy HTTP endpoint.
      hostProxyRef: config/platform-infra/host-proxy.yaml#targets.PK01
      fixedProxy:
        protocol: http
        host: 127.0.0.1
        port: 10809
    unified-pool-group:
      enabled: true
      kind: group
      provider: pool-group
      description: Attach a protected manual account to the unified Codex pool group.
  protected:
    - accountName: unidesk-codex-gptclub-sub2api
      reason: Manually configured in Sub2API as protected; keep outside pool auto-management and sentinel control.
      proxyBinding:
        enabled: true
        source: pk01-host-proxy
        proxyName: platform-infra-sub2api-pk01-local-egress-proxy
      groupBinding:
        enabled: true
        source: unified-pool-group
publicExposure:
  enabled: false
  proxyName: platform-infra-sub2api
  configMapName: sub2api-frpc-config
  deploymentName: sub2api-frpc
  frpcImage: fatedier/frpc:v0.68.1
  serverAddr: 74.48.78.17
  serverPort: 7000
  remotePort: 21880
  localIP: sub2api.platform-infra.svc.cluster.local
  localPort: 8080
  publicBaseUrl: https://sub2api.74-48-78-17.nip.io
  masterBaseUrl: http://127.0.0.1:21880
  masterFrps:
    configPath: /opt/hwlab-frp/frps.dev.toml
    containerName: hwlab-frps-dev
  masterCaddy:
    enabled: true
    domain: sub2api.74-48-78-17.nip.io
    configPath: /etc/caddy/Caddyfile
    serviceName: caddy
    upstreamBaseUrl: http://127.0.0.1:21880
    responseHeaderTimeoutSeconds: 600
    edgeRetry:
      enabled: true
      tryDurationSeconds: 10
      tryIntervalMilliseconds: 250
      retryMatch:
        methods: [POST]
        paths: [/responses/compact]
localCodex:
  backupSuffix: pre-sub2api
  providerName: OpenAI
  wireApi: responses
  modelContextWindow: 272000
  modelAutoCompactTokenLimit: 240000
  supportsWebSockets: false
  responsesWebSocketsV2: false
  responsesSmokeModel: gpt-5.5
sentinel:
  monitor:
    enabled: true
  actions:
    enabled: true
  schedule: "*/1 * * * *"
  image: python:3.12-alpine
  sdk:
    openaiPythonVersion: "2.41.1"
  serviceAccountName: sub2api-account-sentinel
  configMapName: sub2api-account-sentinel-config
  credentialsSecretName: sub2api-account-sentinel-profiles
  stateConfigMapName: sub2api-account-sentinel-state
  cronJobName: sub2api-account-sentinel
  roleName: sub2api-account-sentinel
  roleBindingName: sub2api-account-sentinel
  model: gpt-5.5
  endpoint: responses
  marker:
    prefix: UDSG_OK
    exact: true
  probe:
    timeoutSeconds: 30
    maxOutputTokens: 16
    transportRetryMinutes: 5
    userAgent: Go-http-client/1.1
  gatewayFailureMonitor:
    enabled: true
    lookbackSeconds: 900
    tailLines: 4000
    initialTtlMinutes: 5
    maxTtlMinutes: 30
    backoffMultiplier: 2
    paths:
      - /responses
      - /v1/responses
      - /responses/compact
      - /v1/responses/compact
  cadence:
    successInitialIntervalMinutes: 1
    successMaxIntervalMinutes: 20
    trustedSuccessMaxIntervalMinutes: 20
    untrustedSuccessMaxIntervalMinutes: 2
    successBackoffMultiplier: 2
    jitterPercent: 10
  freeze:
    initialTtlMinutes: 1
    maxTtlMinutes: 10
    backoffMultiplier: 2
    jitterPercent: 10
  pricing:
    usdPer1MInputTokens: 1.25
    usdPer1MOutputTokens: 10
  historyLimit: 200
