Skip to content

Instantly share code, notes, and snippets.

@tyriis
Created June 1, 2026 17:31
Show Gist options
  • Select an option

  • Save tyriis/ac40022242c841a1860e4dc3219be6ea to your computer and use it in GitHub Desktop.

Select an option

Save tyriis/ac40022242c841a1860e4dc3219be6ea to your computer and use it in GitHub Desktop.
{
"title": "OpenCode Token Usage",
"schemaVersion": 39,
"version": 1,
"editable": true,
"timezone": "browser",
"time": { "from": "now-24h", "to": "now" },
"templating": {
"list": [
{ "name": "datasource", "type": "datasource", "query": "prometheus" },
{
"name": "model",
"type": "query",
"datasource": "$datasource",
"query": "label_values(opencode_token_usage_tokens_total, model)",
"includeAll": true,
"multi": true,
"refresh": 1
}
]
},
"panels": [
{
"id": 1,
"type": "stat",
"title": "MTD Input Tokens",
"datasource": "$datasource",
"timeFrom": "now/M",
"fieldConfig": { "defaults": { "unit": "short", "decimals": 0 } },
"targets": [
{
"refId": "A",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"input\",model=~\"$model\"}[$__range]))"
}
],
"gridPos": { "h": 5, "w": 8, "x": 0, "y": 0 }
},
{
"id": 2,
"type": "stat",
"title": "MTD Cached Tokens",
"datasource": "$datasource",
"timeFrom": "now/M",
"fieldConfig": { "defaults": { "unit": "short", "decimals": 0 } },
"targets": [
{
"refId": "A",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"cacheRead\",model=~\"$model\"}[$__range]))"
}
],
"gridPos": { "h": 5, "w": 8, "x": 8, "y": 0 }
},
{
"id": 3,
"type": "stat",
"title": "MTD Output Tokens",
"datasource": "$datasource",
"timeFrom": "now/M",
"fieldConfig": { "defaults": { "unit": "short", "decimals": 0 } },
"targets": [
{
"refId": "A",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"output\",model=~\"$model\"}[$__range]))"
}
],
"gridPos": { "h": 5, "w": 8, "x": 16, "y": 0 }
},
{
"id": 10,
"type": "timeseries",
"title": "Rate - Token In by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (rate(opencode_token_usage_tokens_total{type=\"input\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 21 }
},
{
"id": 11,
"type": "timeseries",
"title": "Rate - Token Cached by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (rate(opencode_token_usage_tokens_total{type=\"cacheRead\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 21 }
},
{
"id": 12,
"type": "timeseries",
"title": "Rate - Token Out by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (rate(opencode_token_usage_tokens_total{type=\"output\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 21 }
},
{
"id": 13,
"type": "timeseries",
"title": "Rate - All Tokens Together",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum(rate(opencode_token_usage_tokens_total{type=\"input\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "input"
},
{
"refId": "B",
"expr": "sum(rate(opencode_token_usage_tokens_total{type=\"cacheRead\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "cached"
},
{
"refId": "C",
"expr": "sum(rate(opencode_token_usage_tokens_total{type=\"output\",model=~\"$model\"}[$__rate_interval]))",
"legendFormat": "output"
}
],
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 29 }
},
{
"id": 20,
"type": "timeseries",
"title": "Cumulative - Token In by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (increase(opencode_token_usage_tokens_total{type=\"input\",model=~\"$model\"}[$__range]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 0, "y": 5 }
},
{
"id": 21,
"type": "timeseries",
"title": "Cumulative - Token Cached by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (increase(opencode_token_usage_tokens_total{type=\"cacheRead\",model=~\"$model\"}[$__range]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 8, "y": 5 }
},
{
"id": 22,
"type": "timeseries",
"title": "Cumulative - Token Out by Model",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum by (model) (increase(opencode_token_usage_tokens_total{type=\"output\",model=~\"$model\"}[$__range]))",
"legendFormat": "{{model}}"
}
],
"gridPos": { "h": 8, "w": 8, "x": 16, "y": 5 }
},
{
"id": 23,
"type": "timeseries",
"title": "Cumulative - All Tokens Together",
"datasource": "$datasource",
"targets": [
{
"refId": "A",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"input\",model=~\"$model\"}[$__range]))",
"legendFormat": "input"
},
{
"refId": "B",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"cacheRead\",model=~\"$model\"}[$__range]))",
"legendFormat": "cached"
},
{
"refId": "C",
"expr": "sum(increase(opencode_token_usage_tokens_total{type=\"output\",model=~\"$model\"}[$__range]))",
"legendFormat": "output"
}
],
"gridPos": { "h": 8, "w": 24, "x": 0, "y": 13 }
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment