CICD-469 · Inference cost per million tokens
Encyclopedia · FinOps and resource optimization · All snippets
Previous · CICD-468 · Next · CICD-470
1. Where it fits
- Placement CI run step or authorized lab terminal.
- Prerequisites authorized read reports, explicit pricing period and reviewed ownership for cleanup.
- Platforms local-linux, github-actions, gitea-actions.
- Parameters
HOURLY_GPU_COST,SECONDS_USED,SPENT_OUTPUT_TOKENS.
2. Copy the snippet
bash
jq -ne --argjson rate "${HOURLY_GPU_COST:?}" --argjson seconds "${SECONDS_USED:?}" --argjson tokens "${SPENT_OUTPUT_TOKENS:?}" '$tokens > 0 and $seconds > 0 and $rate >= 0 | if . then $rate*$seconds/3600*1000000/$tokens else error("invalid cost inputs") end'3. How it works
Multiply the hourly GPU rate by elapsed allocation time and divide by output tokens. The multiplier reports the result per million tokens.
4. Verify the result
Number is cost per million output tokens using elapsed allocated-GPU time. Include total node count and billing overhead for production reports.
Watch for. Use the intended trusted execution context. Keep secret values out of traces, artifacts and debug output.
Validation syntax-validated (Bash parse). Status definitions.