@axemere/gateway-anthropic 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 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,47 @@
1
+ # @axemere/gateway-anthropic
2
+
3
+ [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](../../LICENSE)
4
+
5
+ Drop-in Anthropic client factory for the [Axemere AI Gateway](https://axemere.ai).
6
+
7
+ Returns a standard `Anthropic` instance pre-configured to route through the gateway. All existing Anthropic 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-anthropic
13
+ ```
14
+
15
+ ## Usage
16
+
17
+ ```typescript
18
+ import { anthropicClient } from "@axemere/gateway-anthropic";
19
+
20
+ const client = anthropicClient(); // reads AXEMERE_GATEWAY_URL + AXEMERE_GATEWAY_TOKEN
21
+
22
+ const message = await client.messages.create({
23
+ model: "claude-sonnet-4-6",
24
+ max_tokens: 256,
25
+ messages: [{ role: "user", content: "Hello" }],
26
+ });
27
+ console.log(message.content[0].text);
28
+ ```
29
+
30
+ Streaming works exactly as it does with the standard `@anthropic-ai/sdk` package.
31
+
32
+ ## Configuration
33
+
34
+ | Env var | Description |
35
+ |---------|-------------|
36
+ | `AXEMERE_GATEWAY_URL` | Gateway base URL, e.g. `http://localhost:7080` |
37
+ | `AXEMERE_GATEWAY_TOKEN` | Gateway token issued by the gateway |
38
+
39
+ ## Links
40
+
41
+ - [Axemere AI Gateway](https://axemere.ai)
42
+ - [Documentation](https://axemere.ai/docs)
43
+ - [GitHub](https://github.com/Axemere-LLC/axemere-node)
44
+
45
+ ## License
46
+
47
+ MIT
@@ -0,0 +1,14 @@
1
+ import Anthropic from "@anthropic-ai/sdk";
2
+ import { AiGatewayConfig } from "@axemere/gateway";
3
+ export { AiGatewayConfig };
4
+ /**
5
+ * Creates an Anthropic client pre-configured to route through the Axemere AI Gateway.
6
+ *
7
+ * The returned client is a standard Anthropic instance — use it exactly as you would
8
+ * the official @anthropic-ai/sdk package. All requests are proxied through the gateway,
9
+ * which applies policy, budgets, and records usage.
10
+ *
11
+ * @param config - AiGatewayConfig instance (reads env vars if omitted).
12
+ * @param options - Additional Anthropic constructor options (merged after gateway defaults).
13
+ */
14
+ export declare function anthropicClient(config?: AiGatewayConfig, options?: ConstructorParameters<typeof Anthropic>[0]): Anthropic;
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
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.anthropicClient = anthropicClient;
8
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
9
+ const gateway_1 = require("@axemere/gateway");
10
+ Object.defineProperty(exports, "AiGatewayConfig", { enumerable: true, get: function () { return gateway_1.AiGatewayConfig; } });
11
+ /**
12
+ * Creates an Anthropic client pre-configured to route through the Axemere AI Gateway.
13
+ *
14
+ * The returned client is a standard Anthropic instance — use it exactly as you would
15
+ * the official @anthropic-ai/sdk package. All requests are proxied through the gateway,
16
+ * which applies policy, budgets, and records usage.
17
+ *
18
+ * @param config - AiGatewayConfig instance (reads env vars if omitted).
19
+ * @param options - Additional Anthropic constructor options (merged after gateway defaults).
20
+ */
21
+ function anthropicClient(config, options) {
22
+ const cfg = config ?? new gateway_1.AiGatewayConfig();
23
+ const nativeFetch = typeof globalThis.fetch === "function"
24
+ ? globalThis.fetch.bind(globalThis)
25
+ : undefined;
26
+ return new sdk_1.default({
27
+ baseURL: cfg.proxyUrl("anthropic"),
28
+ apiKey: cfg.gateway_token || "axemere-gateway",
29
+ ...(nativeFetch ? { fetch: nativeFetch } : {}),
30
+ ...options,
31
+ });
32
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,49 @@
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 sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
7
+ const gateway_1 = require("@axemere/gateway");
8
+ const index_1 = require("./index");
9
+ describe("anthropicClient()", () => {
10
+ it("returns an Anthropic instance", () => {
11
+ const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080" });
12
+ const client = (0, index_1.anthropicClient)(cfg);
13
+ expect(client).toBeInstanceOf(sdk_1.default);
14
+ });
15
+ it("uses proxyUrl(anthropic) 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.anthropicClient)(cfg);
24
+ expect(client.baseURL).toBe("http://localhost:7080/proxy/anthropic/k/tok_test/");
25
+ });
26
+ it("falls back to sentinel apiKey when gateway_token is empty", () => {
27
+ const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080", gateway_token: "" });
28
+ const client = (0, index_1.anthropicClient)(cfg);
29
+ expect(client.apiKey).toBe("axemere-gateway");
30
+ });
31
+ it("uses gateway_token as apiKey when set", () => {
32
+ const cfg = new gateway_1.AiGatewayConfig({
33
+ gateway_url: "http://localhost:7080",
34
+ gateway_token: "my_token",
35
+ });
36
+ const client = (0, index_1.anthropicClient)(cfg);
37
+ expect(client.apiKey).toBe("my_token");
38
+ });
39
+ it("constructs with default config when no config passed", () => {
40
+ delete process.env["AXEMERE_GATEWAY_URL"];
41
+ delete process.env["AXEMERE_GATEWAY_TOKEN"];
42
+ expect(() => (0, index_1.anthropicClient)()).not.toThrow();
43
+ });
44
+ it("merges extra options after gateway defaults", () => {
45
+ const cfg = new gateway_1.AiGatewayConfig({ gateway_url: "http://localhost:7080" });
46
+ const client = (0, index_1.anthropicClient)(cfg, { maxRetries: 0 });
47
+ expect(client.maxRetries).toBe(0);
48
+ });
49
+ });
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@axemere/gateway-anthropic",
3
+ "version": "0.1.6",
4
+ "description": "Axemere AI Gateway SDK — Anthropic 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-anthropic"
19
+ },
20
+ "publishConfig": {
21
+ "access": "public"
22
+ },
23
+ "dependencies": {
24
+ "@anthropic-ai/sdk": "^0.36.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
+ }