产品

HTTP API

基础 URL 为 https://promptflowengine.com/api/v1。输入 JSON,输出 JSON。无需身份验证,不存储任何内容;提示词文本从不写入日志。每个响应都带有 x-request-id 响应头。

对于批量处理或敏感内容,请用 CLI 在本地运行同一个引擎:不联网,也没有速率限制。

第一次接触这些集成?连接 PromptFlowEngine 比较了扩展、MCP 和这个 API,并提供经过测试的 TypeScript 客户端和故障排查。

接口

方法路径请求体返回
GET/health—状态、引擎与 API 版本
GET/models—带编码和参考价格的模型目录
GET/rules—规则目录、维度、扣分
POST/analyzeprompt, model?问题、质量、token、安全、需求、意图
POST/validatepromptvalid(无严重问题)、问题
POST/optimizeprompt, model?, mode?, goal?, tokenBudget?选中的候选、带验证结果的全部候选、修改、差异、变化量、建议
POST/restructureprompt, model?, scaffold?分节的提示词、每行标注为 prompt 或 engine 的各部分、计数、前后分析
POST/comparea, b, model?差异、token/成本/质量变化量、已解决和新引入的问题
POST/tokensprompt, model?token 数、计数方式、分节计数、预估成本
POST/scanprompt注入风险与特征、敏感数据的数量与位置、未加分隔的变量
POST/sanitizetext敏感值已替换为占位符的文本

mode:conservative | balanced | structured。goal:tokens | quality | balanced。model:/models 中的任意 id(默认 gpt-4.1)。scaffold:布尔值,默认 true;参见重构。

身份验证

没有。API 不接受密钥、token 或 Cookie,发送了也会被忽略。可以放心地从浏览器、脚本或 Chrome 扩展调用它,因为它不保存任何需要保护的用户数据:每个请求都只根据自己的请求体计算,随后即被丢弃。滥用通过下面的速率限制来约束。

示例

curl
curl -s https://promptflowengine.com/api/v1/optimize \
  -H 'content-type: application/json' \
  -d '{"prompt":"Please summarize the notes. Please summarize the notes.","mode":"balanced"}' \
  | jq '{selected: .selected.text, tokenDelta, changes: [.changes[].title]}'

使用 "goal":"tokens" 时,引擎会改为保留 Please summarize the notes.:句首的 Summarize 要花两个 token,所以这个候选少一个 token。

响应(节选,真实输出)
{
  "selected": "Summarize the notes.",
  "tokenDelta": -4,
  "changes": ["Removed repeated sentences", "Removed filler and politeness phrases"]
}

重构示例

curl
curl -s https://promptflowengine.com/api/v1/restructure \
  -H 'content-type: application/json' \
  -d '{"prompt":"fix login issue and make google login work and dont break anything"}' \
  | jq '{intent, topics, counts, sections: [.sections[].heading]}'
响应(节选)
{
  "intent": "debugging",
  "topics": ["authentication"],
  "counts": { "prompt": 4, "engine": 20, "codebase": 0 },
  "sections": ["Role", "Objective", "Requirements", "Constraints", "Edge cases", "Testing", "Acceptance criteria", "Expected output"]
}

完整的提示词在 text 中。

限制

  • 请求体最大 256 KB;每个文本字段最多 100,000 个字符。
  • 每个客户端 IP 每分钟 60 次 POST 请求。超出时会收到带 retry-after: 60 的 429。
  • CORS 在不带凭据的情况下开放(*),因此浏览器可以直接调用 API。

错误

错误结构
{ "error": { "type": "invalid_request", "message": "\"prompt\" is required.", "requestId": "…" } }
状态码type
400invalid_request:字段缺失或类型错误、JSON 无效、content type 错误
404not_found:未知的接口或 API 版本
405method_not_allowed
413payload_too_large
429rate_limited
500internal_error(不暴露内部细节)

安全

  • 每个字段都会检查类型;未知的模型、模式和目标会被拒绝,而不是去猜测。
  • 响应带有 cache-control: no-store 和一个全部拒绝的 Content Security Policy,因此响应永远不会被当作页面渲染。
  • 日志只记录路由、状态、耗时和大小区间。提示词文本从不写入日志。
  • /scan 和 /analyze 只报告敏感数据的位置,从不返回其值。不要依赖它来保证传输中的保密:请先用 CLI 或 Chrome 扩展在本地脱敏。
  • 提示词只会被当作文本分析,从不被执行或发送给模型,因此输入中的提示词注入无法改变 API 的行为。

支持

问题、更高的限额或 API 的故障:support@promptflowengine.com。请附上请求的路由和错误的 type;切勿发送 API 密钥或包含密钥的提示词文本。