@axemere/gateway-openai 0.1.6
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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +28 -0
- package/dist/index.test.d.ts +1 -0
- package/dist/index.test.js +50 -0
- package/package.json +50 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Axemere LLC
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @axemere/gateway-openai
|
|
2
|
+
|
|
3
|
+
[](../../LICENSE)
|
|
4
|
+
|
|
5
|
+
Drop-in OpenAI client factory for the [Axemere AI Gateway](https://axemere.ai).
|
|
6
|
+
|
|
7
|
+
Returns a standard `OpenAI` instance pre-configured to route through the gateway. All existing OpenAI code works unchanged — the gateway adds cost controls, policy enforcement, and an append-only audit ledger to every call.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @axemere/gateway-openai
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
import { openaiClient } from "@axemere/gateway-openai";
|
|
19
|
+
|
|
20
|
+
const client = openaiClient(); // reads AXEMERE_GATEWAY_URL + AXEMERE_GATEWAY_TOKEN
|
|
21
|
+
|
|
22
|
+
const response = await client.chat.completions.create({
|
|
23
|
+
model: "gpt-4o-mini",
|
|
24
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
25
|
+
});
|
|
26
|
+
console.log(response.choices[0].message.content);
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Streaming works exactly as it does with the standard `openai` package.
|
|
30
|
+
|
|
31
|
+
## Configuration
|
|
32
|
+
|
|
33
|
+
| Env var | Description |
|
|
34
|
+
|---------|-------------|
|
|
35
|
+
| `AXEMERE_GATEWAY_URL` | Gateway base URL, e.g. `http://localhost:7080` |
|
|
36
|
+
| `AXEMERE_GATEWAY_TOKEN` | Gateway token issued by the gateway |
|
|
37
|
+
|
|
38
|
+
## Links
|
|
39
|
+
|
|
40
|
+
- [Axemere AI Gateway](https://axemere.ai)
|
|
41
|
+
- [Documentation](https://axemere.ai/docs)
|
|
42
|
+
- [GitHub](https://github.com/Axemere-LLC/axemere-node)
|
|
43
|
+
|
|
44
|
+
## License
|
|
45
|
+
|
|
46
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
import { AiGatewayConfig } from "@axemere/gateway";
|
|
3
|
+
export { AiGatewayConfig };
|
|
4
|
+
/**
|
|
5
|
+
* Creates an OpenAI client pre-configured to route through the Axemere AI Gateway.
|
|
6
|
+
*
|
|
7
|
+
* The returned client is a standard OpenAI instance — use it exactly as you would
|
|
8
|
+
* the official openai package. All requests are proxied through the gateway, which
|
|
9
|
+
* applies policy, budgets, and records usage.
|
|
10
|
+
*
|
|
11
|
+
* @param config - AiGatewayConfig instance (reads env vars if omitted).
|
|
12
|
+
* @param options - Additional OpenAI constructor options (merged after gateway defaults).
|
|
13
|
+
*/
|
|
14
|
+
export declare function openaiClient(config?: AiGatewayConfig, options?: ConstructorParameters<typeof OpenAI>[0]): OpenAI;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AiGatewayConfig = void 0;
|
|
7
|
+
exports.openaiClient = openaiClient;
|
|
8
|
+
const openai_1 = __importDefault(require("openai"));
|
|
9
|
+
const gateway_1 = require("@axemere/gateway");
|
|
10
|
+
Object.defineProperty(exports, "AiGatewayConfig", { enumerable: true, get: function () { return gateway_1.AiGatewayConfig; } });
|
|
11
|
+
/**
|
|
12
|
+
* Creates an OpenAI client pre-configured to route through the Axemere AI Gateway.
|
|
13
|
+
*
|
|
14
|
+
* The returned client is a standard OpenAI instance — use it exactly as you would
|
|
15
|
+
* the official openai package. All requests are proxied through the gateway, which
|
|
16
|
+
* applies policy, budgets, and records usage.
|
|
17
|
+
*
|
|
18
|
+
* @param config - AiGatewayConfig instance (reads env vars if omitted).
|
|
19
|
+
* @param options - Additional OpenAI constructor options (merged after gateway defaults).
|
|
20
|
+
*/
|
|
21
|
+
function openaiClient(config, options) {
|
|
22
|
+
const cfg = config ?? new gateway_1.AiGatewayConfig();
|
|
23
|
+
return new openai_1.default({
|
|
24
|
+
baseURL: cfg.proxyUrl("openai") + "v1/",
|
|
25
|
+
apiKey: cfg.gateway_token || "axemere-gateway",
|
|
26
|
+
...options,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const openai_1 = __importDefault(require("openai"));
|
|
7
|
+
const gateway_1 = require("@axemere/gateway");
|
|
8
|
+
const index_1 = require("./index");
|
|
9
|
+
describe("openaiClient()", () => {
|
|
10
|
+
it("returns an OpenAI instance", () => {
|
|
11
|
+
const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080" });
|
|
12
|
+
const client = (0, index_1.openaiClient)(cfg);
|
|
13
|
+
expect(client).toBeInstanceOf(openai_1.default);
|
|
14
|
+
});
|
|
15
|
+
it("uses proxyUrl(openai) + v1/ as baseURL", () => {
|
|
16
|
+
const cfg = new gateway_1.AiGatewayConfig({
|
|
17
|
+
gateway_url: "http://localhost:7080",
|
|
18
|
+
gateway_token: "tok_test",
|
|
19
|
+
project_id: "",
|
|
20
|
+
account_id: "",
|
|
21
|
+
customer_id: "",
|
|
22
|
+
});
|
|
23
|
+
const client = (0, index_1.openaiClient)(cfg);
|
|
24
|
+
// OpenAI stores the resolved baseURL on the instance
|
|
25
|
+
expect(client.baseURL).toBe("http://localhost:7080/proxy/openai/k/tok_test/v1/");
|
|
26
|
+
});
|
|
27
|
+
it("falls back to sentinel apiKey when gateway_token is empty", () => {
|
|
28
|
+
const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080", gateway_token: "" });
|
|
29
|
+
const client = (0, index_1.openaiClient)(cfg);
|
|
30
|
+
expect(client.apiKey).toBe("axemere-gateway");
|
|
31
|
+
});
|
|
32
|
+
it("uses gateway_token as apiKey when set", () => {
|
|
33
|
+
const cfg = new gateway_1.AiGatewayConfig({
|
|
34
|
+
gateway_url: "http://localhost:7080",
|
|
35
|
+
gateway_token: "my_token",
|
|
36
|
+
});
|
|
37
|
+
const client = (0, index_1.openaiClient)(cfg);
|
|
38
|
+
expect(client.apiKey).toBe("my_token");
|
|
39
|
+
});
|
|
40
|
+
it("constructs with default config when no config passed", () => {
|
|
41
|
+
delete process.env["AXEMERE_GATEWAY_URL"];
|
|
42
|
+
delete process.env["AXEMERE_GATEWAY_TOKEN"];
|
|
43
|
+
expect(() => (0, index_1.openaiClient)()).not.toThrow();
|
|
44
|
+
});
|
|
45
|
+
it("merges extra options after gateway defaults", () => {
|
|
46
|
+
const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080" });
|
|
47
|
+
const client = (0, index_1.openaiClient)(cfg, { maxRetries: 0, timeout: 5000 });
|
|
48
|
+
expect(client.maxRetries).toBe(0);
|
|
49
|
+
});
|
|
50
|
+
});
|
package/package.json
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@axemere/gateway-openai",
|
|
3
|
+
"version": "0.1.6",
|
|
4
|
+
"description": "Axemere AI Gateway SDK — OpenAI drop-in wrapper",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=18"
|
|
14
|
+
},
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "https://github.com/Axemere-LLC/axemere-node.git",
|
|
18
|
+
"directory": "packages/gateway-openai"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"openai": "^4.0.0",
|
|
25
|
+
"@axemere/gateway": "0.1.6"
|
|
26
|
+
},
|
|
27
|
+
"devDependencies": {
|
|
28
|
+
"typescript": "^5.4.0",
|
|
29
|
+
"@types/node": "^20.0.0",
|
|
30
|
+
"@types/jest": "^29.0.0",
|
|
31
|
+
"jest": "^29.0.0",
|
|
32
|
+
"ts-jest": "^29.0.0"
|
|
33
|
+
},
|
|
34
|
+
"jest": {
|
|
35
|
+
"preset": "ts-jest",
|
|
36
|
+
"testEnvironment": "node",
|
|
37
|
+
"transform": {
|
|
38
|
+
"^.+\\.tsx?$": [
|
|
39
|
+
"ts-jest",
|
|
40
|
+
{
|
|
41
|
+
"useESM": false
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"scripts": {
|
|
47
|
+
"build": "tsc",
|
|
48
|
+
"test": "jest"
|
|
49
|
+
}
|
|
50
|
+
}
|