# Counting errors

> Inspect typed count, model, encoding, capability, and compatibility failures.

- Path: `Guides > Inference > Context Counting > Counting errors`
- Human: https://looprig.com/docs/guides/inference/context-counting/errors
- Machine index: https://looprig.com/llms.txt

Count failures preserve bounded classifications without retaining request bytes.
Inspect them with `errors.As` and `errors.Is`.

## Types

| Error | Meaning |
| --- | --- |
| `EstimatorStateError` | nil estimator or nil context |
| `ModelIdentityError` | invalid model key or identity |
| `UnsupportedAPIFormatError` | no bundled estimator encoder |
| `RequestEncodingError` | selected codec rejected the request |
| `ContextCountError` | callback missing, canceled, model/quality mismatch, or wrapped cause |
| `CapabilityValidationError` | malformed capability metadata |
| `CounterCompatibilityError` | counter weakens inference trust posture |

`ContextCountError.Unwrap` exposes the safe cause. The errors do not include
raw request bodies or provider response content.

## Inspection

```go
var unsupported *contextcount.UnsupportedAPIFormatError
var encoding *contextcount.RequestEncodingError
switch {
case errors.As(err, &unsupported):
	// choose an exact provider counter or reject admission
case errors.As(err, &encoding):
	// fix the request or use a dialect that represents it
}
```

## Source and proof

- [`contextcount/errors.go`](https://github.com/looprig/inference/blob/v0.12.0/contextcount/errors.go)
- [`contextcount/contracts_errors.go`](https://github.com/looprig/inference/blob/v0.12.0/contextcount/contracts_errors.go)
- [`contextcount/estimator_test.go`](https://github.com/looprig/inference/blob/v0.12.0/contextcount/estimator_test.go)

Run `go test ./contextcount`.
