Skip to content

feat(ai): add a cheaperinference provider alias - #128

Open
aiapienthusiast wants to merge 1 commit into
pgrundev:mainfrom
aiapienthusiast:cheaperinference-provider
Open

aiapienthusiast wants to merge 1 commit into
pgrundev:mainfrom
aiapienthusiast:cheaperinference-provider

Conversation

@aiapienthusiast

Copy link
Copy Markdown

What and why

This PR adds PGBOT_AI_PROVIDER=cheaperinference for explain and ask.
It copies the requesty alias (#105) and the opper alias (#118).
No new client code: it reuses the /chat/completions provider.

Cheaper Inference is an OpenAI-compatible LLM gateway.

The alias sets the endpoint to https://api.cheaperinference.com/v1.
It reads the key from CHEAPER_INFERENCE_API_KEY or PGBOT_AI_API_KEY only.
It never takes an OpenAI or OpenRouter key.
It is not added to auto-detection.

export PGBOT_AI_PROVIDER=cheaperinference
export CHEAPER_INFERENCE_API_KEY=…
pgbot explain "$DATABASE_URL"

The default gpt-5.6-terra is served under the same id.
PGBOT_AI_MODEL selects another model, for example gpt-5.4-mini.

Details

Files:

  • internal/ai/openai.go: defaultCheaperInfURL.
  • internal/ai/resolve.go: cheaperinference joins the /chat/completions case. It maps to its endpoint and key variable. keyVarsFor names CHEAPER_INFERENCE_API_KEY.
  • internal/ai/resolve_test.go: TestResolve_cheaperinference, a copy of the opper test.
  • README.md: environment table row and explain section.
  • CHANGELOG.md: entry under Unreleased.

Tests:

  • go test ./internal/ai/, go vet ./internal/ai/ and gofmt -l internal/ai pass.
  • scripts/gate.sh was not run. The Go 1.27 toolchain download is not available on my machine.

Live check: gpt-5.4-mini returned a reply through Resolve() and Generate() with PGBOT_AI_PROVIDER=cheaperinference.

Checklist

  • scripts/gate.sh passes (builds HEAD, not just the working tree)
  • New SQL is read-only; no EXPLAIN ANALYZE; findings stay deterministic (computed in Go) (no SQL change)
  • No PII enters a model.Context / --json / the store
  • --json change is additive, or model.SchemaVersion bumped + schema regenerated (go run ./tools/schemagen) (no --json change)
  • A new finding has a docs/findings/<id>.md page + catalog entry (not applicable)

PGBOT_AI_PROVIDER=cheaperinference points the /chat/completions client at
https://api.cheaperinference.com/v1, the same way the requesty and opper
aliases pick their endpoints. The key comes from CHEAPER_INFERENCE_API_KEY
or PGBOT_AI_API_KEY only, so an OpenAI or OpenRouter key in the shell is
never sent to it, and it is never auto-detected.

Documented in the README environment table and the explain section, and
in the changelog.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant