ambitry 0.1.2 → 0.1.3
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 +2 -0
- package/dist/server.js +14 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -150,6 +150,8 @@ Point a provider at a different upstream — Azure, a gateway, a local model —
|
|
|
150
150
|
|
|
151
151
|
Cost is computed from published per-token rates. Models with no known rate report `null` rather than a guess; a cost dashboard that quietly invents numbers is worse than one that admits ignorance.
|
|
152
152
|
|
|
153
|
+
**One request modification, and the only one.** OpenAI-compatible providers omit token usage from streamed responses unless `stream_options.include_usage` is set, and almost no agent code sets it — so without this, cost and spend caps would be blank for most streaming traffic. Ambitry adds that flag to outgoing OpenAI streaming requests when you haven't set it yourself. The visible effect is one extra terminal chunk carrying usage, which SDKs treat as a normal chunk with no choices. If you set `stream_options` yourself, it's left alone, and Anthropic requests are never modified.
|
|
154
|
+
|
|
153
155
|
## Development
|
|
154
156
|
|
|
155
157
|
```bash
|
package/dist/server.js
CHANGED
|
@@ -33,9 +33,22 @@ export function createServer({ store, controls }) {
|
|
|
33
33
|
examples: ['http://localhost:8787/anthropic', 'http://localhost:8787/openai/v1'],
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
-
|
|
36
|
+
let body = await readBody(req);
|
|
37
37
|
const parsed = parseRequest(route.provider.id, body);
|
|
38
38
|
const requestJson = safeJson(body);
|
|
39
|
+
// OpenAI-compatible providers omit usage from streamed responses unless
|
|
40
|
+
// stream_options.include_usage is set, and almost no agent code sets it.
|
|
41
|
+
// Without this the cost column is empty for most streaming traffic, which
|
|
42
|
+
// guts the spend caps. Anthropic always reports usage, so this is only
|
|
43
|
+
// needed here. The cost is one extra terminal chunk carrying usage, which
|
|
44
|
+
// SDKs treat as a normal chunk with no choices.
|
|
45
|
+
if (route.provider.id === 'openai' && parsed.stream && requestJson && typeof requestJson === 'object') {
|
|
46
|
+
const r = requestJson;
|
|
47
|
+
if (r.stream_options === undefined) {
|
|
48
|
+
r.stream_options = { include_usage: true };
|
|
49
|
+
body = Buffer.from(JSON.stringify(r));
|
|
50
|
+
}
|
|
51
|
+
}
|
|
39
52
|
// Scanned on the way out, so a leak is caught on the request that carries
|
|
40
53
|
// it rather than after the provider has already received it.
|
|
41
54
|
const findings = scanRequest(requestJson);
|