axiomax-esg-sdk-client 1.0.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.
Files changed (4) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +106 -0
  3. package/package.json +44 -0
  4. package/src/index.js +206 -0
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 AXIOMAX LLC, Salinas Puerto Rico
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
+ NOTE: The reference verifier code in this repository is MIT-licensed.
16
+ The AXIOMAX ESG Carbon Shield system architecture, calibration coefficients,
17
+ and brand are proprietary to AXIOMAX LLC and protected by USPTO Patent Pending
18
+ Application 64/081,419 (filed June 3, 2026).
19
+
20
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ # axiomax-esg-sdk
2
+
3
+ Official client SDK for [AXIOMAX ESG Carbon Shield](https://axiomaxllc.com). Cryptographically attest your AI inference workload carbon footprint with one line of code.
4
+
5
+ > Patent Pending USPTO Application **64/081,419** (filed June 3, 2026).
6
+ > Operated by **AXIOMAX LLC**, Salinas, Puerto Rico.
7
+
8
+ ## Install
9
+
10
+ ```bash
11
+ pip install axiomax-esg-sdk
12
+ ```
13
+
14
+ ## Quick start with OpenAI
15
+
16
+ ```python
17
+ from axiomax_esg_sdk import AxiomaxClient, wrap_openai
18
+ import openai
19
+
20
+ axe = AxiomaxClient(license_key="axe_lic_2026_acme_...")
21
+
22
+ # One-line wrap — every chat completion now cryptographically attested
23
+ client = wrap_openai(openai.OpenAI(api_key="..."), axe)
24
+
25
+ # Use OpenAI normally
26
+ response = client.chat.completions.create(
27
+ model="gpt-4",
28
+ messages=[{"role": "user", "content": "hello"}],
29
+ )
30
+
31
+ # Periodically issue a signed token from accumulated records
32
+ token = axe.issue_token()
33
+ print(token["signature_ed25519"])
34
+ ```
35
+
36
+ ## Quick start with Anthropic Claude
37
+
38
+ ```python
39
+ from axiomax_esg_sdk import AxiomaxClient, wrap_anthropic
40
+ import anthropic
41
+
42
+ axe = AxiomaxClient(license_key="axe_lic_...")
43
+ client = wrap_anthropic(anthropic.Anthropic(api_key="..."), axe)
44
+
45
+ response = client.messages.create(
46
+ model="claude-3-5-sonnet-20241022",
47
+ max_tokens=1024,
48
+ messages=[{"role": "user", "content": "hello"}],
49
+ )
50
+ ```
51
+
52
+ ## Quick start with AWS Bedrock
53
+
54
+ ```python
55
+ import boto3
56
+ from axiomax_esg_sdk import AxiomaxClient, wrap_bedrock
57
+
58
+ axe = AxiomaxClient(license_key="axe_lic_...")
59
+ bedrock = wrap_bedrock(boto3.client("bedrock-runtime"), axe)
60
+
61
+ # every invoke_model is now attested (duration only — parse body for token counts)
62
+ response = bedrock.invoke_model(modelId="anthropic.claude-3-sonnet-20240229-v1:0", body=...)
63
+ ```
64
+
65
+ ## Manual recording (any provider)
66
+
67
+ ```python
68
+ from axiomax_esg_sdk import AxiomaxClient
69
+
70
+ axe = AxiomaxClient(license_key="axe_lic_...", soc_profile="apple_m4_pro", region="us_east")
71
+
72
+ # After your inference completes, record metrics:
73
+ axe.record_inference(
74
+ model_id="gpt-4",
75
+ tokens_in=120,
76
+ tokens_out=340,
77
+ duration_ms=1800,
78
+ )
79
+
80
+ # Sign accumulated batch
81
+ token = axe.issue_token()
82
+ ```
83
+
84
+ ## Auto-batching every N seconds
85
+
86
+ ```python
87
+ axe = AxiomaxClient(
88
+ license_key="axe_lic_...",
89
+ batch_interval_sec=3600, # auto-issue token every hour
90
+ )
91
+ ```
92
+
93
+ ## Verification
94
+
95
+ Every issued token is verifiable by any third party at https://verify.axiomaxllc.com or using our open-source verifier `pip install axiomax-esg-verify`.
96
+
97
+ ## License
98
+
99
+ MIT for this SDK. The AXIOMAX ESG Carbon Shield system architecture, calibration coefficients, and brand are proprietary to AXIOMAX LLC (Patent Pending USPTO 64/081,419).
100
+
101
+ ## Links
102
+
103
+ - Main: https://axiomaxllc.com
104
+ - Public verifier: https://verify.axiomaxllc.com
105
+ - Pricing: https://axiomaxllc.com/pricing.html
106
+ - Open-source verifier spec: https://github.com/axiomaxllc/esg-carbon-shield
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "axiomax-esg-sdk-client",
3
+ "version": "1.0.0",
4
+ "description": "Official Node.js SDK for AXIOMAX ESG Carbon Shield. Cryptographically attest your AI inference workload carbon footprint with one line of code. Patent Pending USPTO 64/081,419.",
5
+ "main": "src/index.js",
6
+ "type": "module",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "scripts": {
11
+ "test": "node test/smoke.test.js"
12
+ },
13
+ "keywords": [
14
+ "esg",
15
+ "climate-tech",
16
+ "carbon-accounting",
17
+ "cryptography",
18
+ "ai",
19
+ "openai",
20
+ "anthropic",
21
+ "bedrock",
22
+ "sustainability",
23
+ "csrd",
24
+ "axiomax"
25
+ ],
26
+ "author": "Charles Santana <charles@axiomaxllc.com> (https://axiomaxllc.com)",
27
+ "license": "MIT",
28
+ "homepage": "https://github.com/axiomaxllc/esg-carbon-shield",
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "https://github.com/axiomaxllc/esg-carbon-shield.git"
32
+ },
33
+ "bugs": {
34
+ "url": "https://github.com/axiomaxllc/esg-carbon-shield/issues"
35
+ },
36
+ "files": [
37
+ "src/",
38
+ "README.md",
39
+ "LICENSE"
40
+ ],
41
+ "engines": {
42
+ "node": ">=18.0.0"
43
+ }
44
+ }
package/src/index.js ADDED
@@ -0,0 +1,206 @@
1
+ /**
2
+ * AXIOMAX ESG Carbon Shield — Official Node.js SDK.
3
+ *
4
+ * Cryptographically attest your AI inference workload carbon footprint with one line of code.
5
+ *
6
+ * Patent Pending USPTO 64/081,419. AXIOMAX LLC, Salinas Puerto Rico. MIT License.
7
+ */
8
+
9
+ const DEFAULT_API_BASE = "https://calc.axiomaxllc.com/v1";
10
+
11
+ export class AxiomaxClient {
12
+ /**
13
+ * @param {object} opts
14
+ * @param {string} opts.licenseKey - AXIOMAX license key (axe_lic_*)
15
+ * @param {string} [opts.apiBase] - API base URL (default production)
16
+ * @param {string} [opts.socProfile] - Hardware profile (default "default")
17
+ * @param {string} [opts.region] - Cloud region equivalent (default "default")
18
+ * @param {string} [opts.clientId] - Override (auto from license)
19
+ * @param {number} [opts.batchIntervalSec] - Auto-issue token every N seconds
20
+ */
21
+ constructor({
22
+ licenseKey,
23
+ apiBase = DEFAULT_API_BASE,
24
+ socProfile = "default",
25
+ region = "default",
26
+ clientId = null,
27
+ batchIntervalSec = 0,
28
+ }) {
29
+ if (!licenseKey || !licenseKey.startsWith("axe_lic_")) {
30
+ throw new Error("invalid licenseKey format (must start with 'axe_lic_')");
31
+ }
32
+ this.licenseKey = licenseKey;
33
+ this.apiBase = apiBase.replace(/\/$/, "");
34
+ this.socProfile = socProfile;
35
+ this.region = region;
36
+ this.clientId = clientId || this._deriveClientIdFromLicense(licenseKey);
37
+ this.batchIntervalSec = batchIntervalSec;
38
+
39
+ this._seq = 0;
40
+ this._prevHash = "0".repeat(64);
41
+ this._records = [];
42
+ this._lastBatchAt = Date.now() / 1000;
43
+ }
44
+
45
+ _deriveClientIdFromLicense(key) {
46
+ const parts = key.split("_");
47
+ return parts.length >= 4 ? parts[3] : "unknown";
48
+ }
49
+
50
+ /**
51
+ * Report a single inference. Server applies trade-secret calibration
52
+ * and returns SHA-256 hash + sequence number.
53
+ */
54
+ async recordInference({ modelId, tokensIn, tokensOut, durationMs }) {
55
+ this._seq += 1;
56
+ const payload = {
57
+ client_id: this.clientId,
58
+ api_key: this.licenseKey,
59
+ soc_profile: this.socProfile,
60
+ region: this.region,
61
+ model_id: modelId,
62
+ tokens_in: parseInt(tokensIn),
63
+ tokens_out: parseInt(tokensOut),
64
+ duration_ms: parseInt(durationMs),
65
+ inference_seq: this._seq,
66
+ prev_hash: this._prevHash,
67
+ };
68
+ const r = await fetch(`${this.apiBase}/inference/record`, {
69
+ method: "POST",
70
+ headers: { "Content-Type": "application/json" },
71
+ body: JSON.stringify(payload),
72
+ });
73
+ if (!r.ok) throw new Error(`record_inference failed: ${r.status} ${await r.text()}`);
74
+ const result = await r.json();
75
+ this._prevHash = result.hash || this._prevHash;
76
+ this._records.push({
77
+ seq: result.seq || this._seq,
78
+ hash: this._prevHash,
79
+ tokens_in: tokensIn,
80
+ tokens_out: tokensOut,
81
+ duration_ms: durationMs,
82
+ model_id: modelId,
83
+ });
84
+
85
+ if (this.batchIntervalSec > 0) {
86
+ if (Date.now() / 1000 - this._lastBatchAt >= this.batchIntervalSec) {
87
+ await this.issueToken();
88
+ }
89
+ }
90
+ return result;
91
+ }
92
+
93
+ /**
94
+ * Sign accumulated records into a verifiable ed25519 token. Returns the
95
+ * signed token, or null if no records pending.
96
+ */
97
+ async issueToken() {
98
+ if (this._records.length === 0) return null;
99
+ const payload = {
100
+ client_id: this.clientId,
101
+ api_key: this.licenseKey,
102
+ records: this._records,
103
+ };
104
+ const r = await fetch(`${this.apiBase}/token/issue`, {
105
+ method: "POST",
106
+ headers: { "Content-Type": "application/json" },
107
+ body: JSON.stringify(payload),
108
+ });
109
+ if (!r.ok) throw new Error(`issue_token failed: ${r.status} ${await r.text()}`);
110
+ const token = await r.json();
111
+ this._records = [];
112
+ this._lastBatchAt = Date.now() / 1000;
113
+ return token;
114
+ }
115
+
116
+ status() {
117
+ return {
118
+ clientId: this.clientId,
119
+ seq: this._seq,
120
+ pendingRecords: this._records.length,
121
+ prevHash: this._prevHash,
122
+ apiBase: this.apiBase,
123
+ };
124
+ }
125
+ }
126
+
127
+ /**
128
+ * Wrap an OpenAI client so every chat completion is auto-attested.
129
+ *
130
+ * @example
131
+ * import OpenAI from 'openai';
132
+ * import { AxiomaxClient, wrapOpenAI } from '@axiomax/esg-sdk';
133
+ *
134
+ * const axe = new AxiomaxClient({ licenseKey: 'axe_lic_...' });
135
+ * const client = wrapOpenAI(new OpenAI({apiKey: '...'}), axe);
136
+ * const response = await client.chat.completions.create({model: 'gpt-4', messages: [...]});
137
+ */
138
+ export function wrapOpenAI(openaiClient, axe) {
139
+ const origCreate = openaiClient.chat.completions.create.bind(openaiClient.chat.completions);
140
+ openaiClient.chat.completions.create = async (...args) => {
141
+ const t0 = Date.now();
142
+ const resp = await origCreate(...args);
143
+ const durationMs = Date.now() - t0;
144
+ try {
145
+ const u = resp.usage || {};
146
+ await axe.recordInference({
147
+ modelId: resp.model || args[0]?.model || "unknown",
148
+ tokensIn: u.prompt_tokens || 0,
149
+ tokensOut: u.completion_tokens || 0,
150
+ durationMs,
151
+ });
152
+ } catch (e) {
153
+ // never break user pipeline
154
+ }
155
+ return resp;
156
+ };
157
+ return openaiClient;
158
+ }
159
+
160
+ /**
161
+ * Wrap an Anthropic client so every messages.create is auto-attested.
162
+ */
163
+ export function wrapAnthropic(anthropicClient, axe) {
164
+ const origCreate = anthropicClient.messages.create.bind(anthropicClient.messages);
165
+ anthropicClient.messages.create = async (...args) => {
166
+ const t0 = Date.now();
167
+ const resp = await origCreate(...args);
168
+ const durationMs = Date.now() - t0;
169
+ try {
170
+ const u = resp.usage || {};
171
+ await axe.recordInference({
172
+ modelId: resp.model || args[0]?.model || "unknown",
173
+ tokensIn: u.input_tokens || 0,
174
+ tokensOut: u.output_tokens || 0,
175
+ durationMs,
176
+ });
177
+ } catch (e) {}
178
+ return resp;
179
+ };
180
+ return anthropicClient;
181
+ }
182
+
183
+ /**
184
+ * Wrap an AWS Bedrock runtime so every invokeModel is auto-attested (duration only).
185
+ */
186
+ export function wrapBedrock(bedrockClient, axe) {
187
+ const orig = bedrockClient.invokeModel ? bedrockClient.invokeModel.bind(bedrockClient) : null;
188
+ if (!orig) throw new Error("bedrockClient.invokeModel not found");
189
+ bedrockClient.invokeModel = async (...args) => {
190
+ const t0 = Date.now();
191
+ const resp = await orig(...args);
192
+ const durationMs = Date.now() - t0;
193
+ try {
194
+ await axe.recordInference({
195
+ modelId: args[0]?.modelId || "unknown",
196
+ tokensIn: 0,
197
+ tokensOut: 0,
198
+ durationMs,
199
+ });
200
+ } catch (e) {}
201
+ return resp;
202
+ };
203
+ return bedrockClient;
204
+ }
205
+
206
+ export default { AxiomaxClient, wrapOpenAI, wrapAnthropic, wrapBedrock };