# ISIS v2 WS09-005: RunPod Pay-Per-Second Cost Attribution

## Scope

Implemented first-class pay-per-second RunPod cost attribution for workflow,
project, and tenant dimensions across adapter runtime accounting, API exposure,
SDK contracts, and operations UI.

## Implemented Artifacts

- Runtime attribution contracts:
  - `libs/isis/ai-providers/src/providers/comfy/types.ts`
- RunPod adapter attribution implementation:
  - `libs/isis/ai-providers/src/providers/comfy/runpod-adapter.ts`
  - `libs/isis/ai-providers/src/providers/comfy/runpod-adapter.test.ts`
- Generation API metadata propagation + telemetry:
  - `apps/isis/generation-api/src/middleware/auth.ts`
  - `apps/isis/generation-api/src/routes/jobs.ts`
  - `apps/isis/generation-api/src/services/comfyui.service.ts`
  - `apps/isis/generation-api/src/routes/jobs.spec.ts`
  - `apps/isis/generation-api/src/services/comfyui.service.spec.ts`
  - `apps/isis/generation-api/src/middleware/runpod-budget-guardrail.spec.ts`
- Client and web operations surfacing:
  - `libs/isis/client/src/types.ts`
  - `apps/isis/web/src/pages/RunPodPage.tsx`
  - `apps/isis/web/src/pages/RunPodPage.spec.tsx`
  - `apps/isis/web/src/App.e2e.spec.tsx`

## Attribution Model

- Billing basis remains runtime-derived billable seconds: `ceil(runtimeMs/1000)`
  with configured minimum billable seconds and GPU tier USD/sec pricing.
- Each completed job now records:
  - workflow attribution key (explicit workflow IDs preferred, deterministic
    signature fallback)
  - project attribution key (`projectId`, with unscoped fallback bucket)
  - tenant attribution key (`tenantId` or `organizationId`, with unscoped
    fallback bucket)
  - billable seconds, USD, and credits
- `getCredits()` now returns an `attribution` snapshot with dimension-level
  `credits`, `usd`, and `seconds` maps for `workflow`, `project`, and `tenant`.

## Verification

```bash
pnpm --filter @isis/ai-providers exec vitest run src/providers/comfy/runpod-adapter.test.ts --reporter=dot
pnpm --filter @isis/generation-api exec vitest run src/services/comfyui.service.spec.ts src/routes/jobs.spec.ts src/middleware/runpod-budget-guardrail.spec.ts --reporter=dot
pnpm --filter @isis/web exec vitest run src/pages/RunPodPage.spec.tsx src/pages/JobSubmissionStudio.spec.tsx --reporter=dot
```

## Outcome

WS09-005 is now closed with deterministic per-run pay-per-second accounting and
dimensioned FinOps visibility by workflow, project, and tenant throughout RunPod
operations surfaces.
