Repository navigation
Description
Description
ProPR does not correctly persist LLM costs when using OpenCode with a custom OpenAI-compatible provider through a LiteLLM proxy.
OpenCode emits provider-reported costs in its JSONL output, including part.cost on step_finish events. However, these costs appear to be discarded during parsing and execution-result propagation.
Consequently:
llm_executions.cost_usdis recorded as0.llm_logs.cost_usdis recorded asNULL.- The ProPR UI reports
$0.00for executions that incurred real API costs. - Cost accounting is unreliable for custom provider/model identifiers that aren't present in ProPR's pricing catalog.
Additionally, a long-running execution was observed with a successfully persisted execution summary but no associated llm_execution_details records.
Environment and deployment setup
The following describes the affected self-hosted setup, with private infrastructure identifiers removed.
| Component | Configuration |
|---|---|
| ProPR | 0.9.3, self hosted |
| OpenCode | 1.19.6 (agent container) |
| Agent execution | OpenCode running inside Docker containers managed by ProPR |
| Deployment | Docker Compose on an Ubuntu Linux VPS |
| LiteLLM | Self-hosted LiteLLM Proxy, running as a separate service |
| Upstream model provider | External inference API |
| Model | DeepSeek V4.1 Flash 552B |
| Model configuration | Custom OpenAI-compatible provider through LiteLLM |
| Database | SQLite, WAL mode |
| Git integration | GitHub repositories, issues and pull requests |
LLM request architecture
ProPR
|
| Creates and manages coding-agent execution
v
OpenCode 1.19.6
|
| OpenAI-compatible API
v
Self-hosted LiteLLM Proxy
|
| Routes requests to upstream inference provider
v
DeepSeek V4.1 Flash 552B
|
| Streaming responses
v
OpenCode JSONL events
|
| Usage + step_finish.part.cost
v
ProPR metrics and logging
|
+--> SQLite: llm_executions
+--> SQLite: llm_execution_details
+--> SQLite: llm_logs
Example model identifier
The agent uses a custom provider/model identifier resembling:
opencode-litellm/custom-provider/deepseek-v4.1-flash
This is not necessarily a model ID known to ProPR's pricing catalog.
The upstream model is accessed through LiteLLM using an OpenAI-compatible API endpoint. LiteLLM manages routing, provider credentials and model aliases.
Observed proxy performance
An example request recorded by LiteLLM:
| Metric | Value |
|---|---|
| Prompt tokens | 49,859 |
| Completion tokens | 836 |
| Total duration | 26.671 s |
| Time to first token | 7.590 s |
| LiteLLM overhead | 8 ms |
| Provider-reported request cost | $0.00094875 |
LiteLLM therefore has visibility into actual nonzero API costs, while ProPR records zero or missing costs for completed agent executions.
These figures represent one request, not the complete execution described below.
Steps to reproduce
- Deploy ProPR using Docker Compose with SQLite as its database.
- Configure an OpenCode agent using a custom LiteLLM/OpenAI-compatible provider.
- Select a model whose custom identifier is not necessarily recognized by ProPR's pricing catalog.
- Run a coding task involving multiple model inference steps.
- Confirm that OpenCode emits
step_finishevents withpart.cost. - Allow the execution to complete successfully.
- Inspect the execution metrics:
SELECT
execution_id,
model_name,
input_tokens,
cache_read_input_tokens,
output_tokens,
cost_usd
FROM llm_executions
ORDER BY execution_id DESC
LIMIT 10;- Inspect the corresponding LLM log records:
SELECT
log_id,
session_id,
model_name,
input_tokens,
cache_read_input_tokens,
output_tokens,
cost_usd
FROM llm_logs
ORDER BY log_id DESC
LIMIT 10;- Inspect persisted execution details:
SELECT
execution_id,
COUNT(*) AS detail_count
FROM llm_execution_details
GROUP BY execution_id
ORDER BY execution_id DESC
LIMIT 10;Actual behavior
An observed successful execution produced:
| Metric | llm_executions |
llm_logs |
|---|---|---|
| Duration | 5,983 seconds | 5,983 seconds |
| Input tokens | 33,508,527 | 315,567 |
| Cached input tokens | 33,192,960 | Recorded separately |
| Output tokens | 144,085 | 144,085 |
| Cost | $0.00 | NULL |
| Persisted conversation details | 0 | N/A |
The difference between the input-token fields is consistent:
33,508,527 total input tokens
-33,192,960 cache-read tokens
--------------------------------
315,567 uncached input tokens
The token accounting therefore appears internally consistent.
However, the actual provider cost is not correctly reflected in either database table.
For comparison, a shorter execution persisted 50 conversation-detail records successfully.
Expected behavior
- Actual costs reported by OpenCode should be retained and persisted.
llm_executions.cost_usdandllm_logs.cost_usdshould reflect the actual execution cost.- Provider-reported costs should take precedence over catalog-based estimates when available.
- Catalog-based estimation should remain available when actual costs are missing.
- Missing cost information should not silently be represented as a measured zero.
- Large executions should persist their conversation details reliably, or explicitly report a persistence failure.
Suspected root cause
1. OpenCode costs are not propagated
Relevant source files:
packages/core/src/agents/impl/openCodeParsing.tspackages/core/src/agents/impl/OpenCodeAgent.tspackages/core/src/agents/types.tspackages/core/src/utils/llmLogger.tspackages/core/src/utils/llmMetrics.tssrc/jobs/issueJob/agent.ts
The apparent data flow is:
OpenCode JSONL
|
+-- step_finish.part.tokens
| -> parsed successfully
|
+-- step_finish.part.cost
-> not propagated
|
v
AgentExecutionResult
|
v
toClaudeResult()
|
v
recordLLMMetrics()
|
v
Pricing-catalog fallback
|
v
Custom model pricing unavailable
|
+--> llm_executions.cost_usd = 0
+--> llm_logs.cost_usd = NULL
The agent result type already supports an optional cost field, but the OpenCode parsing and persistence paths do not appear to propagate it consistently.
2. Large conversation logs may fail during database persistence
In packages/core/src/utils/llmMetrics.ts, persistToDatabase() inserts the execution summary before processConversationLog() inserts the detail records.
The conversation details are generated and then inserted together:
const detailsArray = claudeResult.conversationLog.map(
(step, index) =>
buildConversationDetail({
step,
index,
executionId,
conversationLog: claudeResult.conversationLog!,
totalTokens,
costUsd,
})
);
await db('llm_execution_details').insert(detailsArray);For sufficiently large conversation logs, this insertion may exceed SQLite statement or parameter limits.
Because the execution summary is inserted first and persistence errors are caught, an execution can potentially remain recorded even when its details fail to persist.
This second root cause is a hypothesis and requires confirmation through application logs or a reproducible SQLite test.
Suggested fix
- Extract provider-reported costs from OpenCode JSONL events.
- Correctly aggregate incremental costs without double-counting repeated or cumulative events.
- Propagate costs through
AgentExecutionResultand the relevant adapters. - Persist actual costs consistently in both metrics tables.
- Preserve catalog-based fallback pricing.
- Investigate batching or transactional persistence for large conversation logs.
- Add regression tests for custom model identifiers and large execution histories.
Suggested regression tests
- Multiple
step_finishevents with nonzero costs. - Duplicate events and cumulative cost snapshots.
- Missing cost versus explicitly reported zero cost.
- Custom LiteLLM provider without catalog pricing.
- Consistency between
llm_executionsandllm_logs. - Conversation logs containing 500 and 5,000 events.
- SQLite insertion failures and retries.
- Preservation of existing cached-token accounting.
Impact
This affects observability and cost reporting for users running OpenCode with custom or self-hosted OpenAI-compatible providers.
For long-running coding agents, executions can involve millions of cumulative cached tokens and substantial actual API costs while appearing to cost $0.00 in ProPR.
The potentially related execution-detail issue also prevents effective debugging of excessive agent iterations, latency and token consumption.
Activity
roy-tong commentedon Nov 27, 2026
A concrete next check: Bug: OpenCode provider-reported costs are lost, and large executions may have missing detail records. Record the provider-billed request, retry count and accepted result separately; a passing check is not an accepted outcome. Can you share one reproduction?
integry commentedon Dec 1, 2026
Fixed by #3780 (provider-reported OpenCode costs and execution detail records), with the partial-step cost follow-up in #3961 (#3960). Both are on
mainand ship in 0.9.4.roy-tong commentedon Dec 1, 2026
The two failure modes should be separated in the schema: provider-reported cost known, unknown, and catalog-estimated. Storing unknown as 0 makes a later aggregate indistinguishable from a genuinely free call. I would persist the OpenCode
step_finishcost sum with a basis field, keep catalog estimates only when reported cost is absent, and make missing detail persistence fail the execution record rather than leave a summary-only success.