llm-api-purity-check 0.0.0-stage → 1.3.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/LICENSE +27 -0
- package/README.md +161 -2
- package/README_CN.md +122 -0
- package/bin/cli.mjs +415 -0
- package/data/bank.generated.json +1 -0
- package/package.json +39 -4
- package/scripts/sync-bank.mjs +333 -0
- package/skills/aiapipk-check/SKILL.md +134 -0
- package/src/checks.mjs +1273 -0
- package/src/client.mjs +1240 -0
- package/src/fingerprint.mjs +665 -0
- package/src/links.mjs +135 -0
- package/src/modelIdNormalize.mjs +94 -0
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Build-time fingerprint bank synchronization script.
|
|
4
|
+
*
|
|
5
|
+
* Reads (read-only) from ../api-monitor-server/src/data/fingerprintBank/:
|
|
6
|
+
* - bank.generated.json (18 base GPT/Claude reference models + nuisance projection basis)
|
|
7
|
+
* - local.references.json (20 additional multi-family models: DeepSeek, Gemini, Qwen, Kimi, GLM, GPT-6, Claude)
|
|
8
|
+
*
|
|
9
|
+
* Produces a compact, symmetric 38-model offline bank at data/bank.generated.json (< 250 KB):
|
|
10
|
+
* - Strips unused `behavioral` (17.9 KB) dead data and raw per-sample arrays
|
|
11
|
+
* - Drops asymmetric 12-vs-1 `ordered_blocks.environment_centroids` (329+ KB) in favor of
|
|
12
|
+
* symmetric nuisance-projected ordered_blocks centroids (w = 0.4, hellinger = 0.6)
|
|
13
|
+
* - Stores calibrated merged-bank softmax temperatures (1r: 3.5, 2r: 4.5, 3r+: 5.0)
|
|
14
|
+
* - Rounds float vectors to 6 decimal places (~1e-6 precision) for compact npm distribution
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import fs from 'node:fs';
|
|
18
|
+
import path from 'node:path';
|
|
19
|
+
import { fileURLToPath } from 'node:url';
|
|
20
|
+
|
|
21
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
22
|
+
const CLI_ROOT = path.resolve(__dirname, '..');
|
|
23
|
+
const DEFAULT_SERVER_BANK = path.resolve(
|
|
24
|
+
CLI_ROOT,
|
|
25
|
+
'../api-monitor-server/src/data/fingerprintBank/bank.generated.json'
|
|
26
|
+
);
|
|
27
|
+
const DEFAULT_LOCAL_REFS = path.resolve(
|
|
28
|
+
CLI_ROOT,
|
|
29
|
+
'../api-monitor-server/src/data/fingerprintBank/local.references.json'
|
|
30
|
+
);
|
|
31
|
+
const DEFAULT_OUT_PATH = path.resolve(CLI_ROOT, 'data/bank.generated.json');
|
|
32
|
+
|
|
33
|
+
const FP_VALUE_MIN = 1;
|
|
34
|
+
const FP_VALUE_MAX = 355;
|
|
35
|
+
const FP_DIMENSION = FP_VALUE_MAX - FP_VALUE_MIN + 1;
|
|
36
|
+
const FP_ALPHA = 0.5;
|
|
37
|
+
const MAX_TARGET_BYTES = 250 * 1024;
|
|
38
|
+
|
|
39
|
+
function dot(a, b) {
|
|
40
|
+
let s = 0;
|
|
41
|
+
for (let i = 0; i < a.length; i += 1) s += a[i] * b[i];
|
|
42
|
+
return s;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function unit(v) {
|
|
46
|
+
const n = Math.max(Math.sqrt(dot(v, v)), 1e-12);
|
|
47
|
+
return v.map((x) => x / n);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function standardizeWithStats(values, mean, scale) {
|
|
51
|
+
return values.map((v, i) => (v - mean[i]) / scale[i]);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function projectOut(values, basis) {
|
|
55
|
+
const out = values.slice();
|
|
56
|
+
for (const vec of basis || []) {
|
|
57
|
+
const proj = dot(out, vec);
|
|
58
|
+
for (let i = 0; i < out.length; i += 1) out[i] -= proj * vec[i];
|
|
59
|
+
}
|
|
60
|
+
return out;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function countNumbers355(nums) {
|
|
64
|
+
const counts = new Array(FP_DIMENSION).fill(0);
|
|
65
|
+
for (const n of nums) {
|
|
66
|
+
if (n >= FP_VALUE_MIN && n <= FP_VALUE_MAX) counts[n - FP_VALUE_MIN] += 1;
|
|
67
|
+
}
|
|
68
|
+
return counts;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function hellingerFeature(counts) {
|
|
72
|
+
const total = counts.reduce((a, b) => a + b, 0) + FP_ALPHA * FP_DIMENSION;
|
|
73
|
+
return counts.map((v) => Math.sqrt((v + FP_ALPHA) / total));
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function splitIntoFour(values) {
|
|
77
|
+
const base = Math.floor(values.length / 4);
|
|
78
|
+
const rem = values.length % 4;
|
|
79
|
+
const chunks = [];
|
|
80
|
+
let start = 0;
|
|
81
|
+
for (let i = 0; i < 4; i += 1) {
|
|
82
|
+
const size = base + (i < rem ? 1 : 0);
|
|
83
|
+
chunks.push(values.slice(start, start + size));
|
|
84
|
+
start += size;
|
|
85
|
+
}
|
|
86
|
+
return chunks;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function orderedBlockFeature(nums) {
|
|
90
|
+
const pieces = [];
|
|
91
|
+
for (const chunk of splitIntoFour(nums)) {
|
|
92
|
+
const bins = new Array(16).fill(0.5);
|
|
93
|
+
for (const val of chunk) {
|
|
94
|
+
const idx = Math.min(15, Math.floor(((val - 1) / FP_VALUE_MAX) * 16));
|
|
95
|
+
bins[idx] += 1;
|
|
96
|
+
}
|
|
97
|
+
const total = bins.reduce((a, b) => a + b, 0);
|
|
98
|
+
pieces.push(...bins.map((v) => Math.sqrt(v / total)));
|
|
99
|
+
}
|
|
100
|
+
const lastDigits = new Array(10).fill(0.5);
|
|
101
|
+
for (const val of nums) lastDigits[val % 10] += 1;
|
|
102
|
+
const lastTotal = lastDigits.reduce((a, b) => a + b, 0);
|
|
103
|
+
pieces.push(...lastDigits.map((v) => Math.sqrt(v / lastTotal)));
|
|
104
|
+
return pieces;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isDegenerateSample(nums) {
|
|
108
|
+
if (!Array.isArray(nums) || nums.length < 2) return true;
|
|
109
|
+
let stepOne = 0;
|
|
110
|
+
let adjacentRepeat = 0;
|
|
111
|
+
const unique = new Set();
|
|
112
|
+
unique.add(nums[0]);
|
|
113
|
+
for (let i = 1; i < nums.length; i += 1) {
|
|
114
|
+
unique.add(nums[i]);
|
|
115
|
+
if (nums[i] === nums[i - 1]) adjacentRepeat += 1;
|
|
116
|
+
else if (Math.abs(nums[i] - nums[i - 1]) === 1) stepOne += 1;
|
|
117
|
+
}
|
|
118
|
+
const transitions = nums.length - 1;
|
|
119
|
+
if (stepOne / transitions > 0.35) return true;
|
|
120
|
+
if (adjacentRepeat / transitions > 0.35) return true;
|
|
121
|
+
if (unique.size < Math.min(30, nums.length * 0.15)) return true;
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function roundVec(vec, digits = 6) {
|
|
126
|
+
const factor = 10 ** digits;
|
|
127
|
+
return vec.map((v) => Math.round(v * factor) / factor);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseCliArgs(argv) {
|
|
131
|
+
const opts = {
|
|
132
|
+
serverBank: DEFAULT_SERVER_BANK,
|
|
133
|
+
localRefs: DEFAULT_LOCAL_REFS,
|
|
134
|
+
outPath: DEFAULT_OUT_PATH,
|
|
135
|
+
};
|
|
136
|
+
for (let i = 0; i < argv.length; i += 1) {
|
|
137
|
+
const a = argv[i];
|
|
138
|
+
if (a === '--server-bank') opts.serverBank = path.resolve(argv[++i] || '');
|
|
139
|
+
else if (a === '--local-refs') opts.localRefs = path.resolve(argv[++i] || '');
|
|
140
|
+
else if (a === '--out') opts.outPath = path.resolve(argv[++i] || '');
|
|
141
|
+
else throw new Error(`Unknown argument: ${a}`);
|
|
142
|
+
}
|
|
143
|
+
return opts;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
export function buildCompactSyncedBank({
|
|
147
|
+
serverBankPath = DEFAULT_SERVER_BANK,
|
|
148
|
+
localRefsPath = DEFAULT_LOCAL_REFS,
|
|
149
|
+
outPath = DEFAULT_OUT_PATH,
|
|
150
|
+
} = {}) {
|
|
151
|
+
if (!fs.existsSync(serverBankPath)) {
|
|
152
|
+
throw new Error(`Source bank.generated.json not found at ${serverBankPath}`);
|
|
153
|
+
}
|
|
154
|
+
if (!fs.existsSync(localRefsPath)) {
|
|
155
|
+
throw new Error(`Source local.references.json not found at ${localRefsPath}`);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
const rawBase = JSON.parse(fs.readFileSync(serverBankPath, 'utf-8'));
|
|
159
|
+
const baseNumeric = rawBase.numeric;
|
|
160
|
+
if (!baseNumeric || !Array.isArray(baseNumeric.models) || !baseNumeric.robust) {
|
|
161
|
+
throw new Error(`Invalid base bank schema in ${serverBankPath}`);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const localRefs = JSON.parse(fs.readFileSync(localRefsPath, 'utf-8'));
|
|
165
|
+
if (!Array.isArray(localRefs)) {
|
|
166
|
+
throw new Error(`Invalid local.references.json schema in ${localRefsPath}`);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
const minValid = baseNumeric.minimum_valid_numbers || 80;
|
|
170
|
+
const baseH = baseNumeric.robust.hellinger;
|
|
171
|
+
const baseOB = baseNumeric.robust.ordered_blocks;
|
|
172
|
+
|
|
173
|
+
// Clone base models with only inference-required metadata
|
|
174
|
+
const models = baseNumeric.models.map((m) => ({
|
|
175
|
+
id: m.id,
|
|
176
|
+
display_name: m.display_name || m.id,
|
|
177
|
+
family: m.family,
|
|
178
|
+
family_name: m.family_name || m.family,
|
|
179
|
+
counts: m.counts,
|
|
180
|
+
...(Array.isArray(m.aliases) && m.aliases.length > 0 ? { aliases: m.aliases } : {}),
|
|
181
|
+
reference_source: 'modeltrace_base',
|
|
182
|
+
}));
|
|
183
|
+
|
|
184
|
+
const modelOrder = baseNumeric.robust.model_order.slice();
|
|
185
|
+
const hCentroids = baseH.centroids.map((c) => c.slice());
|
|
186
|
+
const obCentroids = baseOB.centroids.map((c) => c.slice());
|
|
187
|
+
|
|
188
|
+
let mergedLocalCount = 0;
|
|
189
|
+
let skippedDegenerateSamples = 0;
|
|
190
|
+
|
|
191
|
+
for (const ref of localRefs) {
|
|
192
|
+
if (!ref || !ref.id || !Array.isArray(ref.samples) || ref.samples.length < 20) continue;
|
|
193
|
+
|
|
194
|
+
const validLengthSamples = ref.samples.filter(
|
|
195
|
+
(nums) => Array.isArray(nums) && nums.length >= minValid
|
|
196
|
+
);
|
|
197
|
+
const cleanSamples = validLengthSamples.filter((nums) => !isDegenerateSample(nums));
|
|
198
|
+
const chosenSamples = cleanSamples.length >= 20 ? cleanSamples : validLengthSamples;
|
|
199
|
+
skippedDegenerateSamples += validLengthSamples.length - chosenSamples.length;
|
|
200
|
+
if (chosenSamples.length < 20) continue;
|
|
201
|
+
|
|
202
|
+
const hc = new Array(FP_DIMENSION).fill(0);
|
|
203
|
+
const oc = new Array(baseOB.feature_mean.length).fill(0);
|
|
204
|
+
const counts = new Array(FP_DIMENSION).fill(0);
|
|
205
|
+
|
|
206
|
+
for (const nums of chosenSamples) {
|
|
207
|
+
for (const n of nums) {
|
|
208
|
+
if (n >= FP_VALUE_MIN && n <= FP_VALUE_MAX) counts[n - FP_VALUE_MIN] += 1;
|
|
209
|
+
}
|
|
210
|
+
const hv = unit(
|
|
211
|
+
projectOut(
|
|
212
|
+
standardizeWithStats(hellingerFeature(countNumbers355(nums)), baseH.feature_mean, baseH.feature_scale),
|
|
213
|
+
baseH.nuisance_basis
|
|
214
|
+
)
|
|
215
|
+
);
|
|
216
|
+
const ovProj = unit(
|
|
217
|
+
projectOut(
|
|
218
|
+
standardizeWithStats(orderedBlockFeature(nums), baseOB.feature_mean, baseOB.feature_scale),
|
|
219
|
+
baseOB.nuisance_basis
|
|
220
|
+
)
|
|
221
|
+
);
|
|
222
|
+
for (let i = 0; i < hc.length; i += 1) hc[i] += hv[i];
|
|
223
|
+
for (let i = 0; i < oc.length; i += 1) oc[i] += ovProj[i];
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const modelDef = {
|
|
227
|
+
id: ref.id,
|
|
228
|
+
display_name: ref.display_name || ref.id,
|
|
229
|
+
family: ref.family,
|
|
230
|
+
family_name: ref.family_name || ref.family,
|
|
231
|
+
counts,
|
|
232
|
+
...(Array.isArray(ref.aliases) && ref.aliases.length > 0 ? { aliases: ref.aliases } : {}),
|
|
233
|
+
...(ref.source ? { reference_source: ref.source } : {}),
|
|
234
|
+
...(ref.captured_at ? { captured_at: ref.captured_at } : {}),
|
|
235
|
+
reference_samples: chosenSamples.length,
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
const existingIdx = models.findIndex((m) => m.id === ref.id);
|
|
239
|
+
if (existingIdx >= 0) {
|
|
240
|
+
models[existingIdx] = modelDef;
|
|
241
|
+
modelOrder[existingIdx] = ref.id;
|
|
242
|
+
hCentroids[existingIdx] = unit(hc);
|
|
243
|
+
obCentroids[existingIdx] = unit(oc);
|
|
244
|
+
} else {
|
|
245
|
+
models.push(modelDef);
|
|
246
|
+
modelOrder.push(ref.id);
|
|
247
|
+
hCentroids.push(unit(hc));
|
|
248
|
+
obCentroids.push(unit(oc));
|
|
249
|
+
}
|
|
250
|
+
mergedLocalCount += 1;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
// Construct compact output (no behavioral dead data, no environment_centroids 12-vs-1 bias, no raw samples)
|
|
254
|
+
const compactBank = {
|
|
255
|
+
numeric: {
|
|
256
|
+
version: 2,
|
|
257
|
+
merged_symmetric: true,
|
|
258
|
+
minimum_valid_numbers: minValid,
|
|
259
|
+
models,
|
|
260
|
+
robust: {
|
|
261
|
+
model_order: modelOrder,
|
|
262
|
+
symmetric_nuisance_ob: true,
|
|
263
|
+
hellinger: {
|
|
264
|
+
feature_mean: roundVec(baseH.feature_mean, 6),
|
|
265
|
+
feature_scale: roundVec(baseH.feature_scale, 6),
|
|
266
|
+
nuisance_basis: baseH.nuisance_basis.map((v) => roundVec(v, 6)),
|
|
267
|
+
centroids: hCentroids.map((v) => roundVec(v, 6)),
|
|
268
|
+
},
|
|
269
|
+
ordered_blocks: {
|
|
270
|
+
weight: 0.4,
|
|
271
|
+
feature_mean: roundVec(baseOB.feature_mean, 6),
|
|
272
|
+
feature_scale: roundVec(baseOB.feature_scale, 6),
|
|
273
|
+
nuisance_basis: baseOB.nuisance_basis.map((v) => roundVec(v, 6)),
|
|
274
|
+
centroids: obCentroids.map((v) => roundVec(v, 6)),
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
calibration: {
|
|
278
|
+
'1': { beta: 3.5, cv_accuracy: null },
|
|
279
|
+
'2': { beta: 4.5, cv_accuracy: null },
|
|
280
|
+
'3': { beta: 5.0, cv_accuracy: null },
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
source: {
|
|
284
|
+
...(rawBase.source && typeof rawBase.source === 'object' ? rawBase.source : {}),
|
|
285
|
+
merged_models: models.length,
|
|
286
|
+
local_models: mergedLocalCount,
|
|
287
|
+
synced_by: 'scripts/sync-bank.mjs',
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
const serialized = JSON.stringify(compactBank);
|
|
292
|
+
const byteSize = Buffer.byteLength(serialized, 'utf-8');
|
|
293
|
+
if (byteSize >= MAX_TARGET_BYTES) {
|
|
294
|
+
throw new Error(
|
|
295
|
+
`Synced bank exceeds target 250KB budget: ${byteSize} bytes (${(byteSize / 1024).toFixed(1)} KB)`
|
|
296
|
+
);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
fs.mkdirSync(path.dirname(outPath), { recursive: true });
|
|
300
|
+
fs.writeFileSync(outPath, serialized, 'utf-8');
|
|
301
|
+
|
|
302
|
+
const familyCounts = {};
|
|
303
|
+
for (const m of models) {
|
|
304
|
+
familyCounts[m.family] = (familyCounts[m.family] || 0) + 1;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return {
|
|
308
|
+
outPath,
|
|
309
|
+
modelCount: models.length,
|
|
310
|
+
mergedLocalCount,
|
|
311
|
+
skippedDegenerateSamples,
|
|
312
|
+
byteSize,
|
|
313
|
+
familyCounts,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
const isMain = process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url);
|
|
318
|
+
if (isMain) {
|
|
319
|
+
const opts = parseCliArgs(process.argv.slice(2));
|
|
320
|
+
const summary = buildCompactSyncedBank({
|
|
321
|
+
serverBankPath: opts.serverBank,
|
|
322
|
+
localRefsPath: opts.localRefs,
|
|
323
|
+
outPath: opts.outPath,
|
|
324
|
+
});
|
|
325
|
+
console.log(
|
|
326
|
+
`[sync-bank] Wrote ${summary.modelCount} models (+${summary.mergedLocalCount} local refs, ` +
|
|
327
|
+
`${summary.skippedDegenerateSamples} degenerate sample(s) filtered) -> ${summary.outPath}`
|
|
328
|
+
);
|
|
329
|
+
console.log(
|
|
330
|
+
`[sync-bank] Size: ${summary.byteSize} bytes (${(summary.byteSize / 1024).toFixed(1)} KB < 250 KB)`
|
|
331
|
+
);
|
|
332
|
+
console.log(`[sync-bank] Families: ${JSON.stringify(summary.familyCounts)}`);
|
|
333
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: aiapipk-check
|
|
3
|
+
description: 使用开源零依赖 CLI(npx llm-api-purity-check)在用户本机直接检测当前或指定的第三方 AI API 中转站/代理渠道是否纯净(暗中提示词注入、条件注入、假流式、输出虚报计费与思考模型豁免、假缓存、38 模型数字指纹防换壳、Anthropic Thinking 签名加密验真、64x64 多模态辨色透传与 16 渠道上游指纹识别)。全程 API Key 零上传本机直测,适用于 Claude Code、Cursor、Codex、Antigravity 等 Coding Agent。
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# AIAPIPK 本机零传 Key 验真技能(`aiapipk-check`)
|
|
7
|
+
|
|
8
|
+
当用户想验证自己当前正在使用(或打算充值)的第三方 AI API 中转站/代理是否存在**暗中提示词注入、条件注入、掉 Prompt Cache、模型换壳掉包、静默降智、伪造 Thinking 签名、阉割图片多模态、假流式或虚报 Token**时,使用本技能在**用户本机直接运行**开源零依赖工具 `npx llm-api-purity-check`。
|
|
9
|
+
|
|
10
|
+
## 核心能力与安全红线
|
|
11
|
+
|
|
12
|
+
- **API Key 零上传**:所有请求由本机 `npx llm-api-purity-check` 直接发往用户指定的目标中转 API,**绝不**将 API Key 发送、上传或粘贴到任何第三方网站、服务器或远端日志。
|
|
13
|
+
- **严禁回显明文 Key**:
|
|
14
|
+
- 优先通过子进程环境变量(`LLM_API_KEY` / `OPENAI_API_KEY` / `ANTHROPIC_API_KEY`)传入,不要把明文 Key 写入持久命令历史或聊天回复;
|
|
15
|
+
- 向用户展示命令或报错时,必须将密钥脱敏为 `sk-****...`(CLI 内置错误体脱敏,Agent 仍须二次自检)。
|
|
16
|
+
- **零外部依赖、高兼容**:
|
|
17
|
+
- 自动剥离中转常见模型前后缀(如 `us.anthropic.`、`-v1:0`、`:thinking`、`[官转]`)并自动推断协议;
|
|
18
|
+
- 原生兼容现代推理模型(GPT-5/6/o1/o3/o4 `max_completion_tokens` 与 HTTP 400 参数自动兼容重试,保留 `stream_options` 不伤缓存判定);
|
|
19
|
+
- 内置与服务端一致的**思考模型计费豁免**(绝不误杀诚实思考模型)与 **38 模型 7 大家族离线数字指纹库**(对称 M2 算法 + 近亲簇 + OOD 门控)。
|
|
20
|
+
|
|
21
|
+
## 一键安装到各大 Coding Agent(面向用户参考)
|
|
22
|
+
|
|
23
|
+
将本文件放到对应客户端的技能目录即可生效:
|
|
24
|
+
|
|
25
|
+
| Coding Agent | 全局技能目录(推荐) | 项目级目录 |
|
|
26
|
+
| :--- | :--- | :--- |
|
|
27
|
+
| **Claude Code** | `~/.claude/skills/aiapipk-check/SKILL.md` | `.claude/skills/aiapipk-check/SKILL.md` |
|
|
28
|
+
| **Cursor** | `~/.cursor/skills/aiapipk-check/SKILL.md` | `.cursor/skills/aiapipk-check/SKILL.md` |
|
|
29
|
+
| **Codex CLI** | `~/.codex/skills/aiapipk-check/SKILL.md` | `.codex/skills/aiapipk-check/SKILL.md` |
|
|
30
|
+
| **Antigravity** | `~/.agents/skills/aiapipk-check/SKILL.md` | `.agents/skills/aiapipk-check/SKILL.md` |
|
|
31
|
+
|
|
32
|
+
一行快速安装命令(示例以 `~/.agents/skills/aiapipk-check` 为例,按客户端替换目标目录即可):
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
mkdir -p ~/.agents/skills/aiapipk-check && \
|
|
36
|
+
curl -fsSL https://raw.githubusercontent.com/yiios/llm-api-purity-check/main/skills/aiapipk-check/SKILL.md \
|
|
37
|
+
-o ~/.agents/skills/aiapipk-check/SKILL.md
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## 第一步:自动识别本机中转配置(不打印明文 Key)
|
|
41
|
+
|
|
42
|
+
优先检查当前客户端的环境变量或配置文件(仅确认是否存在并直接注入子进程环境,绝不把 Key 原文输出给用户或日志):
|
|
43
|
+
|
|
44
|
+
| 客户端 / 协议 | 常见环境变量 / 本地配置 | 推荐 `--protocol` |
|
|
45
|
+
| :--- | :--- | :--- |
|
|
46
|
+
| **Claude Code / Anthropic** | `ANTHROPIC_BASE_URL`、`ANTHROPIC_AUTH_TOKEN` 或 `ANTHROPIC_API_KEY`、`ANTHROPIC_MODEL`(或 `~/.claude/settings.json` 的 `env`) | `anthropic`(含 `claude`/`opus`/`sonnet`/`haiku`/`fable` 时自动推断,自动剥离 `us.anthropic.`/`[官转]`/`-v1:0`) |
|
|
47
|
+
| **Codex CLI / OpenAI Responses** | `OPENAI_BASE_URL`、`OPENAI_API_KEY`、`OPENAI_MODEL`(或 `~/.codex/config.toml`) | `openai-responses`(检测 `/v1/responses` 时建议显式指定) |
|
|
48
|
+
| **Cursor / 通用 OpenAI Chat** | `LLM_BASE_URL` / `OPENAI_BASE_URL`、`LLM_API_KEY` / `OPENAI_API_KEY`、`LLM_MODEL` | `openai-chat`(默认推断) |
|
|
49
|
+
|
|
50
|
+
若本地未配置,直接向用户索取目标 `--base-url`、`--model` 与临时测试 Key(建议优先用低限额、可随时吊销的测试 Key)。
|
|
51
|
+
|
|
52
|
+
## 第二步:分层执行本机检测(低成本优先)
|
|
53
|
+
|
|
54
|
+
确保本机 Node.js >= 18。优先带 `--json` 输出以便精准解析全部结构化字段。
|
|
55
|
+
|
|
56
|
+
### 1. 10 秒快检(默认首轮推荐,花不到一厘钱)
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
LLM_API_KEY="$TARGET_KEY" npx -y llm-api-purity-check \
|
|
60
|
+
--base-url "$TARGET_BASE_URL" \
|
|
61
|
+
--model "$TARGET_MODEL" \
|
|
62
|
+
--checks inject,stream \
|
|
63
|
+
--json
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
> 若测 OpenAI `/v1/responses`(如 Codex 中转),追加 `--protocol openai-responses`。
|
|
67
|
+
|
|
68
|
+
### 2. 全套深度验真(5 大核心项:注入 + 流式/计费 + 真缓存 + 防降智逻辑 + 38 模型指纹)
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
LLM_API_KEY="$TARGET_KEY" npx -y llm-api-purity-check \
|
|
72
|
+
--base-url "$TARGET_BASE_URL" \
|
|
73
|
+
--model "$TARGET_MODEL" \
|
|
74
|
+
--checks inject,stream,cache,logic,fingerprint \
|
|
75
|
+
--rounds 3 \
|
|
76
|
+
--json
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### 3. 进阶专项硬核验真(按需加开关)
|
|
80
|
+
|
|
81
|
+
- **Anthropic Thinking 签名加密往返验真(`--verify-signature`)**:仅对 `anthropic` 协议生效。拿到真实 `thinking + signature` 后,仅追加 2 次 16-token 极短续写(原样 vs 篡改 1 字符),戳穿伪造/剥离官方思考签名的假渠道;若上游未返回签名则自动 `skipped`,绝不误杀。
|
|
82
|
+
- **4 色轮换 64×64 纯色 PNG 多模态辨色透传(`--multimodal`)**:动态生成 64×64 纯色 PNG(红/蓝/绿/黄),验证中转是否真正把图片透传给视觉模型(支持 `openai-chat` / `openai-responses` / `anthropic` 三协议)。
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
# Claude 中转一站式深度体检 + Thinking 签名加密往返 + 多模态辨色
|
|
86
|
+
LLM_API_KEY="$TARGET_KEY" npx -y llm-api-purity-check \
|
|
87
|
+
--base-url "$TARGET_BASE_URL" \
|
|
88
|
+
--model "$TARGET_MODEL" \
|
|
89
|
+
--verify-signature \
|
|
90
|
+
--multimodal \
|
|
91
|
+
--json
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
查看内置 38 款参考模型清单:
|
|
95
|
+
|
|
96
|
+
```bash
|
|
97
|
+
npx -y llm-api-purity-check --list-models
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## 第三步:用人话向用户解读 JSON 报告
|
|
101
|
+
|
|
102
|
+
严格区分**前置连通异常**与**真实作弊风险**,绝不把 401/404/429/WAF 报错误判成模型造假:
|
|
103
|
+
|
|
104
|
+
### 1. 前置错误分型(`status === "error"`)
|
|
105
|
+
|
|
106
|
+
- `auth_error`(401/403):Key 无效、过期或无当前协议权限。
|
|
107
|
+
- `model_not_found`(404 / 无可用渠道):模型名拼写不对、分组未配置或 `--protocol` 选错。
|
|
108
|
+
- `quota_exhausted`(402 / 余额不足):测试 Key 余额/额度耗尽。
|
|
109
|
+
- `rate_limited`(429/529):上游限流或过载,稍后重试。
|
|
110
|
+
- `waf_blocked`:触发 Cloudflare / WAF 拦截,属网络访问问题而非模型作弊。
|
|
111
|
+
|
|
112
|
+
### 2. 逐项解读 7 大维度与 16 渠道指纹
|
|
113
|
+
|
|
114
|
+
- **上游渠道线索(`upstreamChannel`)**:零额外请求从 35+ 安全白名单响应头识别 16 类常见渠道(Cloudflare AI Gateway / OpenRouter / LiteLLM / New-API / One-API / AWS Bedrock / Google Vertex AI / Azure OpenAI / Anthropic Official / OpenAI Official / DeepSeek Official / Alibaba DashScope / Volcengine Ark / Groq / Together AI / SiliconFlow)。**仅作纯信息佐证,`unknown` 绝不扣分。**
|
|
115
|
+
- **提示词注入(`results.inject`)**:`zero`(纯净)、`micro_injection`(轻度开销)、`conditional_injection` / `conditional_tool_injection`(裸请求放行、遇到 Agent UA 或工具才暗中注词)、`heavy_injection` / `tamper_detected`(重度全局注入或 `/v1/responses` 回显指令/工具篡改)。
|
|
116
|
+
- **流式、计费与思考模型豁免(`results.stream`)**:汇报 `ttftMs`、`tps`、`responseModel`、`fakeStreamSuspect`。若 `thinkingExempt === true`(已扣除 `reasoningTokens`,或存在真实 `thinkingChars` / 思考签名且倍率 `< 8.0x`),明确告知用户“属于诚实思考消耗,已自动豁免,未判虚报”。仅 `billingInflationSuspect === true` 时才报虚报计费风险。
|
|
117
|
+
- **真 Prompt Caching(`results.cache`)**:`cacheHitRate >= 0.6` 正常;`0%` 提示掉缓存/假缓存风险,Coding Agent 长期费用会被放大 5~10 倍。
|
|
118
|
+
- **动态防降智推理(`results.logic`)**:对比 `parsed` 与 `expected`;若 `hitTrap === true` 说明掉入弱模型常见跳步陷阱,存在降智嫌疑。
|
|
119
|
+
- **38 模型 1–355 数字指纹(`results.fingerprint`)**:
|
|
120
|
+
- `matched`:与宣称模型吻合(若 `siblingClusterMatched === true`,温和说明“命中同家族近亲簇,属正常统计重叠”)。
|
|
121
|
+
- `not_in_bank`:未入库或绝对拟合度未过门控(`topRawH`/`topRawOB`/`topJsSimilarity`),已保守拒识。
|
|
122
|
+
- `low_confidence`:样本波动或命中非直连/老化基线(参考 `baselineProvenanceWarning`),不作红牌定性。
|
|
123
|
+
- `mismatch` / `family_mismatch`:高置信度指向其他型号或跨家族模型,附 `topCandidates` 前 3 名提示换壳风险。
|
|
124
|
+
- **Thinking 签名加密往返(`results.signature`,启用 `--verify-signature` 时)**:
|
|
125
|
+
- `verified`(通过):原样签名放行(200)且篡改 1 字符被加密校验拒绝(400/422),证明经过真实 Anthropic 签名验证。
|
|
126
|
+
- `tampered_accepted`(高危 `fail`):篡改 1 字符后的假签名仍返回 200,高度怀疑上游剥离或伪造了 Claude Thinking 签名。
|
|
127
|
+
- `intact_rejected`(警告 `warn`):原样签名被拒,可能存在跨轮路由漂移或块字段损坏。
|
|
128
|
+
- `skipped`(信息 `info`):非 Anthropic 协议或模型未开启/未返回签名,绝不扣分。
|
|
129
|
+
- **64×64 纯色 PNG 多模态(`results.multimodal`,启用 `--multimodal` 时)**:对比 `expectedColor` 与 `detectedColor`,通过则证明图像已真实透传并被视觉模型正确辨色;答错颜色或丢图判 `fail`;若上游明确返回该模型不支持视觉则报 `warn`(`vision_unsupported`)。
|
|
130
|
+
|
|
131
|
+
## 第四步:给出可执行建议
|
|
132
|
+
|
|
133
|
+
- 全项通过:简明给出“当前中转配置本机实测纯净”的结论,提醒定期复测。
|
|
134
|
+
- 检出高风险(注入 / 0% 缓存 / 虚报 / 换壳 / 伪造签名 / 丢图):按严重程度列出具体实测证据,并附上 `report.links` 引导用户在 [AIAPIPK 目录雷达](https://www.aiapipk.com/directory/) 核查该站历史口碑与实时状态,或前往 [AIAPIPK 在线验真](https://www.aiapipk.com/detect/) 补充 Pelican/Zebra SVG 实画对照与精确 Tokenizer 复算。
|