Go API gateway that proxies OpenAI Chat, Responses, and Anthropic Messages to OpenCode / Claude backends.
cmd/opencode2api/main.go: binary entrypoint; keep thin.internal/app/: all logic —server.go,chat.go,responses*.go,claude*.go,anthropic*.go,count_tokens.go,config.go,admin.go,launch*.go,stats.go.internal/domain/,internal/ids/,internal/random/: shared types and helpers.docs/:API.md,CONFIGURATION.md,DEPLOYMENT.md,RELEASE.md— update with behavior changes.scripts/:release.sh,build-release.sh,install.sh;Dockerfile,config.example.jsonat root.
make build: builds version-stamped binary tobin/opencode2api.make test/go test ./...: full test suite.go test ./internal/app -run TestName -v: single focused test.make vet/make fmt:go vetandgofmt -w ./cmd ./internal../bin/opencode2api: run locally; copiesconfig.example.jsontoconfig.jsonas starting point.
- Go 1.22, tabs,
gofmt-clean; runmake fmtbefore pushing. - Follow existing file layout:
*_protocol.gofor wire types,*.gofor handlers,*_test.gobeside code. - Exported symbols use
CamelCase, locals short but clear; no single-letter globals. - Protocol fixes go in the matching converter (e.g.
responses_passthrough.go), notserver.go.
- Standard
go testwith table-driven cases; seeprotocol_regression_test.go,request_compatibility_test.go. - Name tests
Test<Area>_<Case>, e.g.TestResponses_PassthroughRelay. - Add or update a regression test for any Chat/Responses/SSE mapping change.
- Verify streaming with
[DONE]sentinel and event-order assertions where applicable.
- Use Conventional Commits:
feat(scope):,fix(scope):,chore:,docs:,style(admin):— e.g.fix(responses): append missing [DONE] sentinel. - Keep commits scoped; release chores (
chore: prepare vX.Y.Z) stay separate. - PRs: describe behavior change, link issue, list tests run (
make test,make vet), include SSE/JSON samples or admin screenshots for protocol/UI changes.
- Never commit
config.json, API keys, or*.log; useconfig.example.jsonas template. - Validate auth, admin, and proxy-key paths after touching
auth.goorconfig.go. - Keep
Dockerfile/deploy/in sync when changing ports, paths, or env vars.