Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ PORT=20123
# against the host network; keep it false unless you control the URL sources.
# OPENCODE_ALLOW_PRIVATE_MEDIA_URLS=true

# Size and count limits. ONE attachment may not exceed MAX_ATTACHMENT_BYTES;
# the whole request may not exceed MAX_ATTACHMENT_BYTES across attachments.
# Size and count limits. The same byte budget applies to one attachment and to
# the combined total per request: an attachment that would push the request over
# the budget is dropped entirely and its name is recorded in the prompt.
# OPENCODE_MAX_ATTACHMENT_BYTES=20971520
# OPENCODE_MAX_ATTACHMENTS=16
# OPENCODE_MEDIA_FETCH_TIMEOUT_MS=15000
Expand Down
21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,18 @@ When nothing is found the request fails with:
| --- | --- | --- |
| `POST` | `/v1/chat/completions` | OpenAI Chat Completions: streaming and non-streaming, tools, images, `reasoning_effort`. |
| `POST` | `/v1/responses` | OpenAI Responses API with its typed SSE event sequence. |
| `POST` | `/v1/completions` | Legacy OpenAI completions: a prompt string (an array prompt requires `n: 1`) mapped to one user turn, streamed or buffered. |
| `POST` | `/v1/messages` | Anthropic Messages: streaming and non-streaming, `thinking`, `tool_use`. |
| `POST` | `/v1/messages/count_tokens` | Anthropic token-count estimate for a Messages body. |
| `POST` | `/v1/embeddings` | Always `501` — OpenCode exposes no embedding model. |
| `GET` | `/v1/models` | List models, with gateway extensions: `name`, `context_length`, `max_output_tokens`, `capabilities`, `reasoning`, `status`, `enabled`. |
| `GET` | `/v1/models/{id}` | One model by `provider/model` or bare id. |
| `GET` | `/health` | Liveness plus upstream readiness snapshot (public). |
| `GET` | `/ready` | Readiness: `200` only when an upstream server and a model catalog are available (public). |
| `GET` | `/ready` | Readiness from cached state: `200` only when an upstream server is resolved and a model catalog is already cached (public, never calls upstream). |
| `GET` | `/healthz` | Minimal liveness alias (public). |
| `GET` | `/metrics` | Prometheus exposition (requires a key unless `OPENCODE_METRICS_PUBLIC=true`). |
| `GET` | `/admin/status` | Config, upstream, catalog and session-cache snapshot. |
| `GET` | `/admin/config` | The effective configuration, with secrets redacted. |
| `POST` | `/admin/models/refresh` | Force a model catalog reload. |
| `GET` | `/admin/sessions` | List sticky sessions. |
| `DELETE` | `/admin/sessions` | Drop every sticky session. |
Expand Down Expand Up @@ -480,19 +482,22 @@ Every variable, with types, defaults and security notes:

* **`GET /health`** — liveness plus `upstream.ready` and `upstream.source`
(`env`, `spawned`, `discovered`). Public, like `/ready` and `/healthz`.
* **`GET /ready`** — `200` only when an upstream server answers and the model
catalog loads; `503` with `upstream.error` otherwise. Use it for container
readiness and load-balancer gating.
* **`GET /ready`** — `200` only when an upstream endpoint is resolved and a model
catalog is already **cached**; `503` with `upstream.error` otherwise. It never
calls upstream, so an anonymous probe cannot trigger work: force a refresh with
the authenticated `POST /admin/models/refresh`. Use it for container readiness
and load-balancer gating.
* **`GET /metrics`** — Prometheus text format from `prom-client`, prefix
`opencode_api_`: `http_requests_total`, `http_request_duration_seconds`,
`upstream_requests_total`, `upstream_request_duration_seconds`,
`tokens_total`, `completions_total`, `active_streams`, `upstream_restarts_total`,
`session_cache_entries`, `event_stream_connected`, plus process defaults. Requires a key unless
`OPENCODE_METRICS_PUBLIC=true`.
* **`/admin/*`** — `/admin/status` (config, upstream binary and URL, catalog
counts, session count), `/admin/models/refresh`, `/admin/sessions` (list and
delete-all), `/admin/upstream/restart`. Authenticated; restrict them at the
proxy if you expose the gateway.
counts, session count), `/admin/config` (effective configuration with API keys
and the upstream password redacted), `/admin/models/refresh`, `/admin/sessions`
(list and delete-all), `/admin/upstream/restart`. Authenticated; restrict them
at the proxy if you expose the gateway.
* **Request correlation.** Send `x-request-id` (up to 128 characters from
`A-Za-z0-9._:-`) and the gateway echoes it on the response and uses it as the
request id in its logs; anything else is replaced by a generated id. Streaming
Expand Down Expand Up @@ -606,7 +611,7 @@ opencode-api/ # package name; the project is "OpenCode API"
│ ├── adapter/
│ │ ├── anthropic/ # /v1/messages, /v1/messages/count_tokens
│ │ ├── common/ # reasoning mapping, tool bridge, usage maths
│ │ └── openai/ # /v1/chat/completions, /v1/responses, /v1/models, /v1/embeddings
│ │ └── openai/ # /v1/chat/completions, /v1/responses, /v1/completions, /v1/models, /v1/embeddings
│ ├── http/ # SSE writer, client-disconnect signal
│ ├── media/ # data URI, remote fetch, local path resolution
│ ├── metrics/ # Prometheus registry
Expand Down
Loading