SPHIOR API
API 参考
SPHIOR Security API 让您可以扫描任何语言、框架或环境的代码漏洞,并将确定性的修复指引交给您自己的 AI 代理。
身份验证
身份验证
所有请求必须在 Authorization 头中包含您的 API 密钥作为 Bearer 令牌。
bash
curl https://api.sphior.com/v1/scan \
-H "Authorization: Bearer sk_live_your_api_key_here" \
-H "Content-Type: application/json"切勿在客户端代码或公共仓库中暴露您的 API 密钥。请使用环境变量或密钥管理器。
在以下位置生成和管理 API 密钥: API 控制台。每个账户最多 5 个有效密钥。
POST
/v1/scan扫描代码
分析代码片段的安全漏洞。返回包含严重性、CVSS 评分、行号和修复建议的结果。完全确定性(无 AI):相同代码始终产生相同结果——可复现、可用于审计。
请求体
| 参数 | 类型 | 描述 |
|---|---|---|
| coderequired | string | 要分析的源代码。最大大小取决于您的计划(10KB–10MB)。 |
| languagerequired | string | 编程语言: javascript, typescript, python, go, java, ruby, php, sql |
| policy_id | string | 要应用的自定义策略 ID(Business+ 计划)。默认为 OWASP 规则集。 |
请求示例
bash
curl -X POST https://api.sphior.com/v1/scan \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{
"code": "app.get(\"/user\", (req, res) => { db.query(\"SELECT * FROM users WHERE id=\" + req.query.id) })",
"language": "javascript"
}'响应示例
json
{
"scan_id": "scan_01j9x7z3k8q4b5c2d6e7f8g9h0",
"status": "completed",
"language": "javascript",
"findings": [
{
"id": "find_001",
"type": "sql_injection",
"severity": "critical",
"cvss": 9.8,
"line": 2,
"column": 11,
"message": "Unsanitized user input passed directly to SQL query",
"cwe": "CWE-89",
"owasp": "A03:2021",
"fix_hint": "Use parameterized queries: db.query('SELECT * FROM users WHERE id = ?', [req.query.id])"
}
],
"summary": {
"critical": 1, "high": 0, "medium": 0, "low": 0, "info": 0
},
"ai_calls": 0,
"cached": false,
"latency_ms": 12
}POST
/v1/fix获取修复指引
根据之前扫描的 finding ID,返回确定性的修复指引——问题原因、修复步骤、位置以及给 AI 代理的指示。SPHIOR 不编写补丁也不传输您的源代码;由您自己的 AI(通过 MCP)应用修复。
请求体
| 参数 | 类型 | 描述 |
|---|---|---|
| scan_idrequired | string | 之前 /v1/scan 调用返回的 ID。 |
| finding_idrequired | string | 要生成修复的特定发现。 |
| context | string | 额外的周围代码上下文(建议提供完整文件以获得最佳结果)。 |
响应示例
json
{
"fix_id": "fix_01j9x8a1b2c3d4e5f6g7h8i9j0",
"scan_id": "scan_01j9x7z3k8q4b5c2d6e7f8g9h0",
"finding_id": "find_001",
"patched_code": null,
"fix_context": {
"finding_id": "find_001",
"rule_id": "pattern.js.sql_concat",
"severity": "critical",
"cwe": "CWE-89",
"owasp": "A03:2021",
"why": "OS command / SQL injection: untrusted input reaches the query and can execute arbitrary statements.",
"remediation_steps": [
"Review the flagged code and identify the interpolated value.",
"Use a parameterized query (e.g. WHERE id = ?) with bound parameters.",
"Add a regression test covering the fixed behavior."
],
"agent_instructions": "Open the file in your workspace and read the actual code yourself (it is NOT included here). Apply the remediation steps. A human must review your change before merge.",
"data_boundary_note": "SPHIOR does not transmit your source code. This payload contains only finding metadata and deterministic remediation guidance."
},
"latency_ms": 9
}GET
/v1/rules列出规则
列出您的计划可用的所有活跃安全规则。返回规则 ID、类别、严重性和适用语言。Business+ 计划可以通过控制台创建自定义规则。
bash
curl https://api.sphior.com/v1/rules \
-H "Authorization: Bearer sk_live_..." \
-G -d "language=javascript" -d "severity=critical"查询参数
| 参数 | 类型 | 描述 |
|---|---|---|
| language | string | 按语言筛选(如 python, go)。省略则显示所有语言。 |
| severity | string | 按严重性筛选: critical, high, medium, low, info |
| category | string | 按 OWASP 类别筛选(如 injection, auth, crypto) |
Webhook
在 API 控制台中注册 webhook URL,以便在扫描完成、检测到严重漏洞或达到支出上限时接收实时事件。
事件类型
scan.completed扫描完成时触发。负载包含 scan_id、摘要和发现数量。
scan.critical_found检测到严重漏洞时立即触发。
spend_cap.reached月度支出达到配置上限时触发。
spend_cap.warning支出达到上限的 80% 时触发。
Webhook 负载使用您的 webhook 密钥通过 HMAC-SHA256 签名。处理前请务必验证 X-SPHIOR-Signature 头。
错误代码
SPHIOR API 使用标准 HTTP 状态码。错误响应为包含 error 和 code 字段的 JSON。
| 状态 | 代码 | 含义 |
|---|---|---|
| 401 | unauthenticated | 缺少或无效的 API 密钥。 |
| 403 | forbidden | 该密钥没有此操作的权限。 |
| 400 | invalid_request | 格式错误的 JSON、缺少必填字段或不支持的语言。 |
| 413 | payload_too_large | 代码大小超出您的计划限制。 |
| 429 | spend_cap_reached | 已达到每月支出上限。仅返回规则结果。 |
| 429 | rate_limited | 每秒请求过多。请退避后重试。 |
| 500 | internal_error | 意外的服务器错误。请使用指数退避重试。 |
json
// Error response shape
{
"error": "Missing required field: language",
"code": "invalid_request",
"status": 400
}SDK
官方 SDK 支持 TypeScript/JavaScript 和 Python。两者都封装了 REST API,提供类型化响应、自动重试和支出上限感知。
TypeScript / Node.js
bash
npm install @sphior/sdktypescript
import { SphiorClient } from "@sphior/sdk";
const sphior = new SphiorClient({ apiKey: process.env.SPHIOR_API_KEY });
const result = await sphior.scan({
code: fs.readFileSync("./auth.ts", "utf8"),
language: "typescript",
});
for (const finding of result.findings) {
console.log(`${finding.severity.toUpperCase()}: ${finding.message} (line ${finding.line})`);
console.log("Fix hint:", finding.fix_hint);
}
// Hand a finding to your own AI agent to fix (deterministic guidance, no code sent):
const guidance = await sphior.fix({ scan_id: result.scan_id, finding_id: result.findings[0].id });
console.log(guidance.fix_context.remediation_steps);Python
bash
pip install sphior-sdkpython
from sphior import SphiorClient
client = SphiorClient(api_key=os.environ["SPHIOR_API_KEY"])
result = client.scan(
code=open("app.py").read(),
language="python",
)
for finding in result.findings:
print(f"{finding.severity.upper()}: {finding.message} (line {finding.line})")
print("Fix hint:", finding.fix_hint)
# Hand a finding to your own AI agent to fix (deterministic guidance, no code sent):
guidance = client.fix(scan_id=result.scan_id, finding_id=result.findings[0].id)
print(guidance.fix_context["remediation_steps"])定价
SPHIOR Security API 采用简单的平台访问费。扫描与修复指引运行在完全确定性引擎上——没有按 AI 调用计费。各计划的差异在于速率限制、代码大小限制和支持。
| Plan | Platform fee | Scanning | Fix guidance |
|---|---|---|---|
| Free | $0/mo | Included | Included |
| Developer | $29/mo | Included | Included |
| Business | $99/mo | Included | Included |
| Enterprise | $299+/mo | Included | Included |
确定性引擎使成本稳定且可预测。每秒速率限制和代码大小限制按计划扩展;在 API 控制台中配置。
