llm-api-purity-check 1.2.0 → 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/README.md +75 -32
- package/README_CN.md +64 -29
- package/bin/cli.mjs +147 -26
- package/data/bank.generated.json +1 -1
- package/package.json +3 -2
- package/scripts/sync-bank.mjs +333 -0
- package/skills/aiapipk-check/SKILL.md +134 -0
- package/src/checks.mjs +794 -58
- package/src/client.mjs +1000 -98
- package/src/fingerprint.mjs +326 -44
- package/src/links.mjs +12 -5
- package/src/modelIdNormalize.mjs +94 -0
- package/test/links.test.mjs +0 -60
- package/test/purity.test.mjs +0 -186
package/bin/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { callLlm, inferProtocol } from '../src/client.mjs';
|
|
2
|
+
import { callLlm, inferProtocol, isReasoningCapableModel } from '../src/client.mjs';
|
|
3
3
|
import {
|
|
4
4
|
attributeFingerprint,
|
|
5
5
|
generateFingerprintChallenges,
|
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
runCacheCheck,
|
|
10
10
|
runInjectionProbe,
|
|
11
11
|
runLogicCheck,
|
|
12
|
+
runMultimodalCheck,
|
|
13
|
+
runSignatureRoundtripCheck,
|
|
12
14
|
runStreamAndTamperCheck,
|
|
13
15
|
} from '../src/checks.mjs';
|
|
14
16
|
import { buildContextualFooter } from '../src/links.mjs';
|
|
@@ -17,7 +19,7 @@ const HELP = `
|
|
|
17
19
|
llm-api-purity-check — Audit third-party LLM API proxies for hidden prompt injection,
|
|
18
20
|
model substitution, downgrade, fake Prompt Caching, instruction/tools tampering & token inflation.
|
|
19
21
|
|
|
20
|
-
Online zero-install web verifier (
|
|
22
|
+
Online zero-install web verifier (38-model bank + SVG visual comparison + live 370+ provider benchmark):
|
|
21
23
|
https://www.aiapipk.com/detect/ | https://www.aiapipk.com/
|
|
22
24
|
|
|
23
25
|
Usage:
|
|
@@ -28,16 +30,18 @@ Options:
|
|
|
28
30
|
--api-key <key> API key (or set env LLM_API_KEY / OPENAI_API_KEY / ANTHROPIC_API_KEY)
|
|
29
31
|
--model <name> Claimed model name (e.g. claude-sonnet-4-5, gpt-5, deepseek-chat)
|
|
30
32
|
--protocol <type> openai-chat | openai-responses | anthropic (auto-inferred if omitted)
|
|
31
|
-
--checks <list> Comma-separated: inject,stream,cache,logic,fingerprint (default: all)
|
|
33
|
+
--checks <list> Comma-separated: inject,stream,cache,logic,fingerprint,signature,multimodal (default: all)
|
|
32
34
|
--rounds <n> Number of 1-355 fingerprint sampling rounds (default: 3, range: 1-5)
|
|
35
|
+
--verify-signature Run optional Anthropic Thinking cryptographic signature roundtrip check
|
|
36
|
+
--multimodal Run optional 4-color rotating 64x64 solid PNG vision pass-through check
|
|
33
37
|
--json Emit machine-readable JSON report to stdout
|
|
34
38
|
--list-models List reference models bundled in the 1-355 fingerprint bank
|
|
35
39
|
-h, --help Show this help message
|
|
36
40
|
|
|
37
41
|
Examples:
|
|
38
42
|
node bin/cli.mjs --base-url https://api.example.com --api-key sk-xxx --model claude-sonnet-4-5
|
|
39
|
-
node bin/cli.mjs --base-url https://api.example.com --api-key sk-xxx --model claude-
|
|
40
|
-
node bin/cli.mjs --base-url https://api.example.com --api-key sk-xxx --model gpt-5 --protocol openai-responses --checks inject,cache,stream
|
|
43
|
+
node bin/cli.mjs --base-url https://api.example.com --api-key sk-xxx --model claude-opus-4-6 --checks inject,stream --verify-signature
|
|
44
|
+
node bin/cli.mjs --base-url https://api.example.com --api-key sk-xxx --model gpt-5 --protocol openai-responses --checks inject,cache,stream --multimodal
|
|
41
45
|
node bin/cli.mjs --list-models
|
|
42
46
|
`;
|
|
43
47
|
|
|
@@ -49,6 +53,8 @@ function parseArgs(argv) {
|
|
|
49
53
|
protocol: '',
|
|
50
54
|
checks: 'all',
|
|
51
55
|
rounds: 3,
|
|
56
|
+
verifySignature: false,
|
|
57
|
+
multimodal: false,
|
|
52
58
|
json: false,
|
|
53
59
|
listModels: false,
|
|
54
60
|
help: false,
|
|
@@ -58,6 +64,8 @@ function parseArgs(argv) {
|
|
|
58
64
|
if (a === '-h' || a === '--help') opts.help = true;
|
|
59
65
|
else if (a === '--json') opts.json = true;
|
|
60
66
|
else if (a === '--list-models') opts.listModels = true;
|
|
67
|
+
else if (a === '--verify-signature') opts.verifySignature = true;
|
|
68
|
+
else if (a === '--multimodal') opts.multimodal = true;
|
|
61
69
|
else if (a === '--base-url') opts.baseUrl = argv[++i] || '';
|
|
62
70
|
else if (a === '--api-key') opts.apiKey = argv[++i] || '';
|
|
63
71
|
else if (a === '--model') opts.model = argv[++i] || '';
|
|
@@ -69,9 +77,33 @@ function parseArgs(argv) {
|
|
|
69
77
|
return opts;
|
|
70
78
|
}
|
|
71
79
|
|
|
80
|
+
function formatCheckError(err) {
|
|
81
|
+
return {
|
|
82
|
+
status: 'error',
|
|
83
|
+
errorKind: err?.errorKind || 'request_error',
|
|
84
|
+
httpStatus: err?.httpStatus ?? null,
|
|
85
|
+
error: err?.message || String(err),
|
|
86
|
+
...(err?.hint ? { hint: err.hint } : {}),
|
|
87
|
+
...(err?.upstreamChannel ? { upstreamChannel: err.upstreamChannel } : {}),
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function pickBestUpstreamChannel(results) {
|
|
92
|
+
let fallback = null;
|
|
93
|
+
for (const r of Object.values(results || {})) {
|
|
94
|
+
const ch = r?.upstreamChannel;
|
|
95
|
+
if (!ch) continue;
|
|
96
|
+
if (ch.channel && ch.channel !== 'unknown') return ch;
|
|
97
|
+
if (!fallback) fallback = ch;
|
|
98
|
+
}
|
|
99
|
+
return fallback || { channel: 'unknown', label: 'Unknown / Generic Relay', confidence: 'none', signals: [] };
|
|
100
|
+
}
|
|
101
|
+
|
|
72
102
|
async function runFingerprintCheck({ baseUrl, apiKey, protocol, model, rounds, log }) {
|
|
73
103
|
const challenges = generateFingerprintChallenges(rounds);
|
|
104
|
+
const maxTokens = isReasoningCapableModel(model) ? 4096 : 1600;
|
|
74
105
|
const outputs = [];
|
|
106
|
+
let upstreamChannel = null;
|
|
75
107
|
for (let i = 0; i < challenges.length; i += 1) {
|
|
76
108
|
const ch = challenges[i];
|
|
77
109
|
log(` [fingerprint] round ${i + 1}/${challenges.length} (requesting ${ch.expectedCount} integers 1..355)...`);
|
|
@@ -82,8 +114,11 @@ async function runFingerprintCheck({ baseUrl, apiKey, protocol, model, rounds, l
|
|
|
82
114
|
model,
|
|
83
115
|
userPrompt: ch.prompt,
|
|
84
116
|
stream: false,
|
|
85
|
-
maxTokens
|
|
117
|
+
maxTokens,
|
|
86
118
|
});
|
|
119
|
+
if (!upstreamChannel || (upstreamChannel.channel === 'unknown' && res.upstreamChannel?.channel !== 'unknown')) {
|
|
120
|
+
upstreamChannel = res.upstreamChannel || null;
|
|
121
|
+
}
|
|
87
122
|
outputs.push({ text: res.text, expectedCount: ch.expectedCount });
|
|
88
123
|
}
|
|
89
124
|
const attr = attributeFingerprint(outputs, model);
|
|
@@ -93,7 +128,7 @@ async function runFingerprintCheck({ baseUrl, apiKey, protocol, model, rounds, l
|
|
|
93
128
|
: attr.claimedMatchStatus === 'mismatch' || attr.claimedMatchStatus === 'family_mismatch'
|
|
94
129
|
? 'fail'
|
|
95
130
|
: 'warn';
|
|
96
|
-
return { status, ...attr };
|
|
131
|
+
return { status, ...attr, upstreamChannel };
|
|
97
132
|
}
|
|
98
133
|
|
|
99
134
|
async function main() {
|
|
@@ -108,7 +143,7 @@ async function main() {
|
|
|
108
143
|
for (const m of bank.models) {
|
|
109
144
|
console.log(` - ${m.id.padEnd(34)} [${m.family}] ${m.display_name || ''}`);
|
|
110
145
|
}
|
|
111
|
-
console.log(
|
|
146
|
+
console.log(`\nFull ${bank.models.length}-model live bank + SVG downgrade comparison: https://www.aiapipk.com/detect/`);
|
|
112
147
|
process.exit(0);
|
|
113
148
|
}
|
|
114
149
|
|
|
@@ -123,6 +158,8 @@ async function main() {
|
|
|
123
158
|
opts.checks === 'all'
|
|
124
159
|
? new Set(['inject', 'stream', 'cache', 'logic', 'fingerprint'])
|
|
125
160
|
: new Set(opts.checks.split(',').map((s) => s.trim().toLowerCase()).filter(Boolean));
|
|
161
|
+
if (opts.verifySignature) enabled.add('signature');
|
|
162
|
+
if (opts.multimodal) enabled.add('multimodal');
|
|
126
163
|
|
|
127
164
|
const log = opts.json ? () => {} : (msg) => console.log(msg);
|
|
128
165
|
log(`\nAIAPIPK llm-api-purity-check`);
|
|
@@ -141,6 +178,8 @@ async function main() {
|
|
|
141
178
|
results: {},
|
|
142
179
|
};
|
|
143
180
|
|
|
181
|
+
let capturedSignatureTrace = null;
|
|
182
|
+
|
|
144
183
|
if (enabled.has('inject')) {
|
|
145
184
|
log('1) Running 10-second A/B/C single-char prompt-injection probe...');
|
|
146
185
|
try {
|
|
@@ -151,21 +190,26 @@ async function main() {
|
|
|
151
190
|
model: opts.model,
|
|
152
191
|
});
|
|
153
192
|
} catch (err) {
|
|
154
|
-
report.results.inject =
|
|
193
|
+
report.results.inject = formatCheckError(err);
|
|
155
194
|
}
|
|
156
195
|
}
|
|
157
196
|
|
|
158
197
|
if (enabled.has('stream')) {
|
|
159
198
|
log('2) Running streaming cadence, metadata & tamper check...');
|
|
160
199
|
try {
|
|
161
|
-
|
|
200
|
+
const streamRes = await runStreamAndTamperCheck({
|
|
162
201
|
baseUrl: opts.baseUrl,
|
|
163
202
|
apiKey: opts.apiKey,
|
|
164
203
|
protocol,
|
|
165
204
|
model: opts.model,
|
|
166
205
|
});
|
|
206
|
+
if (streamRes._signatureTrace) {
|
|
207
|
+
capturedSignatureTrace = streamRes._signatureTrace;
|
|
208
|
+
delete streamRes._signatureTrace;
|
|
209
|
+
}
|
|
210
|
+
report.results.stream = streamRes;
|
|
167
211
|
} catch (err) {
|
|
168
|
-
report.results.stream =
|
|
212
|
+
report.results.stream = formatCheckError(err);
|
|
169
213
|
}
|
|
170
214
|
}
|
|
171
215
|
|
|
@@ -179,7 +223,7 @@ async function main() {
|
|
|
179
223
|
model: opts.model,
|
|
180
224
|
});
|
|
181
225
|
} catch (err) {
|
|
182
|
-
report.results.cache =
|
|
226
|
+
report.results.cache = formatCheckError(err);
|
|
183
227
|
}
|
|
184
228
|
}
|
|
185
229
|
|
|
@@ -193,7 +237,7 @@ async function main() {
|
|
|
193
237
|
model: opts.model,
|
|
194
238
|
});
|
|
195
239
|
} catch (err) {
|
|
196
|
-
report.results.logic =
|
|
240
|
+
report.results.logic = formatCheckError(err);
|
|
197
241
|
}
|
|
198
242
|
}
|
|
199
243
|
|
|
@@ -209,10 +253,40 @@ async function main() {
|
|
|
209
253
|
log,
|
|
210
254
|
});
|
|
211
255
|
} catch (err) {
|
|
212
|
-
report.results.fingerprint =
|
|
256
|
+
report.results.fingerprint = formatCheckError(err);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
if (enabled.has('signature')) {
|
|
261
|
+
log('6) Running Anthropic Thinking cryptographic signature roundtrip check...');
|
|
262
|
+
try {
|
|
263
|
+
report.results.signature = await runSignatureRoundtripCheck({
|
|
264
|
+
baseUrl: opts.baseUrl,
|
|
265
|
+
apiKey: opts.apiKey,
|
|
266
|
+
protocol,
|
|
267
|
+
model: opts.model,
|
|
268
|
+
seedTrace: capturedSignatureTrace,
|
|
269
|
+
});
|
|
270
|
+
} catch (err) {
|
|
271
|
+
report.results.signature = formatCheckError(err);
|
|
213
272
|
}
|
|
214
273
|
}
|
|
215
274
|
|
|
275
|
+
if (enabled.has('multimodal')) {
|
|
276
|
+
log('7) Running 4-color 64x64 solid PNG multimodal vision pass-through check...');
|
|
277
|
+
try {
|
|
278
|
+
report.results.multimodal = await runMultimodalCheck({
|
|
279
|
+
baseUrl: opts.baseUrl,
|
|
280
|
+
apiKey: opts.apiKey,
|
|
281
|
+
protocol,
|
|
282
|
+
model: opts.model,
|
|
283
|
+
});
|
|
284
|
+
} catch (err) {
|
|
285
|
+
report.results.multimodal = formatCheckError(err);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
report.upstreamChannel = pickBestUpstreamChannel(report.results);
|
|
216
290
|
const footerLinks = buildContextualFooter({
|
|
217
291
|
baseUrl: opts.baseUrl,
|
|
218
292
|
model: opts.model,
|
|
@@ -226,10 +300,19 @@ async function main() {
|
|
|
226
300
|
}
|
|
227
301
|
|
|
228
302
|
console.log('\n==================== AUDIT SUMMARY ====================');
|
|
303
|
+
if (report.upstreamChannel) {
|
|
304
|
+
const sigStr =
|
|
305
|
+
report.upstreamChannel.signals?.length > 0
|
|
306
|
+
? ` (${report.upstreamChannel.signals.slice(0, 3).join(', ')})`
|
|
307
|
+
: '';
|
|
308
|
+
console.log(`[INFO] Upstream Hint : ${report.upstreamChannel.label}${sigStr}`);
|
|
309
|
+
}
|
|
229
310
|
if (report.results.inject) {
|
|
230
311
|
const j = report.results.inject;
|
|
231
|
-
if (j.status === 'error')
|
|
232
|
-
|
|
312
|
+
if (j.status === 'error') {
|
|
313
|
+
console.log(`[ERROR:${j.errorKind}] Inject Probe : ${j.error}`);
|
|
314
|
+
if (j.hint) console.log(` Hint : ${j.hint}`);
|
|
315
|
+
} else {
|
|
233
316
|
const deltaA = j.deltaAgent != null ? `${j.deltaAgent >= 0 ? '+' : ''}${j.deltaAgent}` : '-';
|
|
234
317
|
const deltaT = j.deltaTool != null ? `${j.deltaTool >= 0 ? '+' : ''}${j.deltaTool}` : '-';
|
|
235
318
|
console.log(
|
|
@@ -241,18 +324,23 @@ async function main() {
|
|
|
241
324
|
}
|
|
242
325
|
if (report.results.stream) {
|
|
243
326
|
const s = report.results.stream;
|
|
244
|
-
if (s.status === 'error')
|
|
245
|
-
|
|
327
|
+
if (s.status === 'error') {
|
|
328
|
+
console.log(`[ERROR:${s.errorKind}] Stream/Tamper : ${s.error}`);
|
|
329
|
+
if (s.hint) console.log(` Hint : ${s.hint}`);
|
|
330
|
+
} else {
|
|
331
|
+
const thinkNote = s.thinkingExempt ? ` | thinkingExempt=${s.thinkingExemptReason}` : '';
|
|
246
332
|
console.log(
|
|
247
|
-
`[${s.status.toUpperCase()}] Stream/Tamper : TTFT=${s.ttftMs}ms | TPS=${s.tps} | chunks=${s.chunkCount} | fakeStream=${s.fakeStreamSuspect} | respModel=${s.responseModel || '-'}`
|
|
333
|
+
`[${s.status.toUpperCase()}] Stream/Tamper : TTFT=${s.ttftMs}ms | TPS=${s.tps} | chunks=${s.chunkCount} | fakeStream=${s.fakeStreamSuspect} | respModel=${s.responseModel || '-'}${thinkNote}`
|
|
248
334
|
);
|
|
249
335
|
if (s.warnings?.length) console.log(` Warnings : ${s.warnings.join(', ')}`);
|
|
250
336
|
}
|
|
251
337
|
}
|
|
252
338
|
if (report.results.cache) {
|
|
253
339
|
const c = report.results.cache;
|
|
254
|
-
if (c.status === 'error')
|
|
255
|
-
|
|
340
|
+
if (c.status === 'error') {
|
|
341
|
+
console.log(`[ERROR:${c.errorKind}] Prompt Cache : ${c.error}`);
|
|
342
|
+
if (c.hint) console.log(` Hint : ${c.hint}`);
|
|
343
|
+
} else {
|
|
256
344
|
console.log(
|
|
257
345
|
`[${c.status.toUpperCase()}] Prompt Cache : hitRate=${Math.round(c.cacheHitRate * 100)}% (R2 cached=${c.round2.cachedTokens}/${c.round2.inputTokens}) | TTFT R1=${c.round1.ttftMs}ms -> R2=${c.round2.ttftMs}ms`
|
|
258
346
|
);
|
|
@@ -260,8 +348,10 @@ async function main() {
|
|
|
260
348
|
}
|
|
261
349
|
if (report.results.logic) {
|
|
262
350
|
const l = report.results.logic;
|
|
263
|
-
if (l.status === 'error')
|
|
264
|
-
|
|
351
|
+
if (l.status === 'error') {
|
|
352
|
+
console.log(`[ERROR:${l.errorKind}] Logic Puzzle : ${l.error}`);
|
|
353
|
+
if (l.hint) console.log(` Hint : ${l.hint}`);
|
|
354
|
+
} else {
|
|
265
355
|
console.log(
|
|
266
356
|
`[${l.status.toUpperCase()}] Logic Puzzle : parsed=${l.parsed} | expected=${l.expected} | trap=${l.trapAnswer}${l.hitTrap ? ' (HIT SKIP-STEP TRAP!)' : ''}`
|
|
267
357
|
);
|
|
@@ -269,16 +359,47 @@ async function main() {
|
|
|
269
359
|
}
|
|
270
360
|
if (report.results.fingerprint) {
|
|
271
361
|
const f = report.results.fingerprint;
|
|
272
|
-
if (f.status === 'error')
|
|
273
|
-
|
|
362
|
+
if (f.status === 'error') {
|
|
363
|
+
console.log(`[ERROR:${f.errorKind}] Fingerprint : ${f.error}`);
|
|
364
|
+
if (f.hint) console.log(` Hint : ${f.hint}`);
|
|
365
|
+
} else {
|
|
274
366
|
const top3 = (f.topCandidates || [])
|
|
275
367
|
.slice(0, 3)
|
|
276
368
|
.map((x) => `${x.modelId} (${Math.round(x.probability * 100)}%)`)
|
|
277
369
|
.join(', ');
|
|
370
|
+
const siblingNote = f.siblingClusterMatched ? ' [sibling-cluster]' : '';
|
|
278
371
|
console.log(
|
|
279
|
-
`[${f.status.toUpperCase()}] Fingerprint : status=${f.claimedMatchStatus} | top=${f.prediction || '-'} (${Math.round((f.probability || 0) * 100)}%) | family=${f.familyPrediction || '-'}`
|
|
372
|
+
`[${f.status.toUpperCase()}] Fingerprint : status=${f.claimedMatchStatus}${siblingNote} | top=${f.prediction || '-'} (${Math.round((f.probability || 0) * 100)}%) | family=${f.familyPrediction || '-'} | bank=${f.bankModelCount}`
|
|
280
373
|
);
|
|
281
374
|
if (top3) console.log(` Top 3 : ${top3}`);
|
|
375
|
+
if (f.topRawH != null) {
|
|
376
|
+
console.log(
|
|
377
|
+
` Fit Metrics : rawH=${f.topRawH} | rawOB=${f.topRawOB} | js=${f.topJsSimilarity}${f.degenerateRejectedCount ? ` | degRejected=${f.degenerateRejectedCount}` : ''}`
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
if (f.baselineProvenanceWarning) {
|
|
381
|
+
console.log(` Baseline Note : ${f.baselineProvenanceWarning}`);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
if (report.results.signature) {
|
|
386
|
+
const sig = report.results.signature;
|
|
387
|
+
if (sig.status === 'error') {
|
|
388
|
+
console.log(`[ERROR:${sig.errorKind}] Thinking Sig : ${sig.error}`);
|
|
389
|
+
if (sig.hint) console.log(` Hint : ${sig.hint}`);
|
|
390
|
+
} else {
|
|
391
|
+
console.log(`[${sig.status.toUpperCase()}] Thinking Sig : verdict=${sig.verdict} | ${sig.summary}`);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
if (report.results.multimodal) {
|
|
395
|
+
const mm = report.results.multimodal;
|
|
396
|
+
if (mm.status === 'error') {
|
|
397
|
+
console.log(`[ERROR:${mm.errorKind}] Multimodal : ${mm.error}`);
|
|
398
|
+
if (mm.hint) console.log(` Hint : ${mm.hint}`);
|
|
399
|
+
} else {
|
|
400
|
+
console.log(
|
|
401
|
+
`[${mm.status.toUpperCase()}] Multimodal : expected=${mm.expectedColor} | detected=${mm.detectedColor || '-'} | png=${mm.pngDimensions || '64x64'} (${mm.pngBytes ?? '-'}B)`
|
|
402
|
+
);
|
|
282
403
|
}
|
|
283
404
|
}
|
|
284
405
|
console.log('=======================================================');
|