@openhoo/hoopilot 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -97,20 +97,7 @@ $env:OPENAI_BASE_URL = "http://127.0.0.1:4141/v1"
97
97
  $env:OPENAI_API_KEY = "local-key"
98
98
  ```
99
99
 
100
- Use with Codex CLI after Hoopilot is running:
101
-
102
- ```powershell
103
- $env:OPENAI_API_KEY = "local-key"
104
- codex -m gpt-5.5 -c 'model_reasoning_effort="xhigh"' -c 'openai_base_url="http://127.0.0.1:4141/v1"'
105
- ```
106
-
107
- One-line PowerShell form:
108
-
109
- ```powershell
110
- $env:OPENAI_API_KEY = "local-key"; codex -m gpt-5.5 -c 'model_reasoning_effort="xhigh"' -c 'openai_base_url="http://127.0.0.1:4141/v1"'
111
- ```
112
-
113
- Or use the bundled `codexx` convenience command after Hoopilot is already running:
100
+ Use with Codex CLI after Hoopilot is running, via the bundled `codexx` command. It runs Codex against the local server with the right model provider — selecting `gpt-5.5` over Copilot's Responses API, which a plain `openai_base_url` override does not configure (see the note below):
114
101
 
115
102
  ```powershell
116
103
  $env:HOOPILOT_API_KEY = "local-key"
@@ -167,6 +154,18 @@ Equivalent environment variables:
167
154
 
168
155
  Incoming `x-request-id` headers are preserved on responses. If a request has no ID, Hoopilot generates one and returns it as `x-request-id`.
169
156
 
157
+ ## Metrics and usage
158
+
159
+ Hoopilot tracks token usage, request counts, and latency in memory while the server runs, and can report your GitHub Copilot account quota (premium-request "credit" usage).
160
+
161
+ - `GET /metrics` returns Prometheus text (`text/plain; version=0.0.4`). It exposes request counters (`hoopilot_requests_total`), upstream call counters (`hoopilot_upstream_requests_total`), token counters by model and type (`hoopilot_tokens_total{model,type}`), a request-duration histogram (`hoopilot_request_duration_seconds`), an in-flight gauge, and—once `/v1/usage` has been fetched at least once—Copilot quota gauges (`hoopilot_copilot_quota_remaining{category}`, `_entitlement`, `_used`, `_percent_remaining`). Counters reset to zero on restart, which Prometheus handles natively.
162
+ - `GET /v1/usage` returns JSON combining the proxy metrics snapshot with live Copilot quota fetched from GitHub (cached for 60 seconds). If the quota cannot be read, `copilot` is `null` and `copilot_error` explains why, but the proxy metrics are still returned.
163
+ - `hoopilot usage` prints your Copilot plan and quota from the command line.
164
+
165
+ Token usage is read from the upstream `usage` object. For streaming chat completions, usage is only available when the client sends `stream_options: {"include_usage": true}`; Hoopilot never injects it, so streamed chat requests without that flag contribute request and latency metrics but not token counts. The Responses API always reports usage, so streamed Responses requests are fully accounted.
166
+
167
+ `/metrics` and `/v1/usage` are subject to the same `HOOPILOT_API_KEY` gate as the other routes.
168
+
170
169
  ## Authentication
171
170
 
172
171
  Hoopilot supports one credential flow: GitHub Copilot OAuth browser login.
@@ -184,6 +183,7 @@ Supported authentication-related settings:
184
183
  - `HOOPILOT_GITHUB_CLIENT_ID`: GitHub OAuth app client ID override. The default uses the same GitHub Copilot OAuth app as opencode's Copilot provider.
185
184
  - `HOOPILOT_GITHUB_DOMAIN`: GitHub domain override. Default: `github.com`.
186
185
  - `COPILOT_API_BASE_URL`: upstream Copilot API base URL override. Default: `https://api.githubcopilot.com`.
186
+ - `HOOPILOT_GITHUB_API_BASE_URL`: GitHub REST API base URL used for the Copilot quota lookup. Default: `https://api.github.com`.
187
187
 
188
188
  ## Codex Auth Errors
189
189
 
@@ -203,7 +203,7 @@ Then, in another PowerShell session:
203
203
  $env:OPENAI_API_KEY = "local-key"
204
204
  Invoke-RestMethod -Headers @{ Authorization = "Bearer $env:OPENAI_API_KEY" } `
205
205
  http://127.0.0.1:4141/v1/models
206
- codex -m gpt-5.5 -c 'model_reasoning_effort="xhigh"' -c 'openai_base_url="http://127.0.0.1:4141/v1"'
206
+ codexx
207
207
  ```
208
208
 
209
209
  If that returns `401 copilot_auth_error`, rerun `npx @openhoo/hoopilot login` and confirm the GitHub account has active Copilot access.
@@ -214,6 +214,7 @@ If that returns `401 copilot_auth_error`, rerun `npx @openhoo/hoopilot login` an
214
214
  hoopilot [serve] [options]
215
215
  hoopilot login [options]
216
216
  hoopilot models [options]
217
+ hoopilot usage [options]
217
218
  ```
218
219
 
219
220
  Commands:
@@ -222,6 +223,7 @@ Commands:
222
223
  serve Start the proxy server (default)
223
224
  login Sign in through GitHub OAuth in a browser and verify Copilot access
224
225
  models List available GitHub Copilot model IDs
226
+ usage Show GitHub Copilot quota and premium-request usage
225
227
  update, upgrade Update hoopilot to the latest release
226
228
  ```
227
229
 
@@ -230,7 +232,7 @@ Options:
230
232
  ```txt
231
233
  -p, --port <port> Port to listen on. Default: 4141
232
234
  --host <host> Host to listen on. Default: 127.0.0.1
233
- --api-key <key> Require clients to send Authorization: Bearer <key>
235
+ --api-key <key> Require clients to send Authorization: Bearer <key> or x-api-key: <key>
234
236
  --auth-file <path> OAuth credential store path
235
237
  --copilot-api-base-url <url> Copilot API base URL override
236
238
  --log-level <level> trace, debug, info, warn, error, fatal, or silent
@@ -242,12 +244,14 @@ Options:
242
244
  ## Endpoints
243
245
 
244
246
  - `GET /healthz`
247
+ - `GET /metrics`
245
248
  - `GET /v1/models`
249
+ - `GET /v1/usage`
246
250
  - `POST /v1/chat/completions`
247
251
  - `POST /v1/responses`
248
252
  - `POST /v1/completions`
249
253
 
250
- `/v1/chat/completions` and `/v1/responses` are proxied to the matching Copilot endpoints as directly as possible. `/v1/completions` translates legacy completion requests and responses to the closest chat completions equivalent.
254
+ `/v1/chat/completions` and `/v1/responses` are proxied to the matching Copilot endpoints as directly as possible. `/v1/completions` translates legacy completion requests and responses to the closest chat completions equivalent. `GET /metrics` and `GET /v1/usage` report proxy metrics and Copilot quota (see [Metrics and usage](#metrics-and-usage)).
251
255
 
252
256
  ## Development
253
257