跳到正文

POST /api/qr/ai/generate

与 /api/qr/generate 使用同一个渲染器,但你只需用一句话描述想要的效果,引擎就会选择形状、颜色和码眼。

AI 端点有三个变体,请选择与你的认证方式相匹配的那个。

市场:自带 LLM 密钥

POST https://api.qr-branding.com/api/qr/ai/generate

curl -X POST https://api.qr-branding.com/api/qr/ai/generate \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Proxy-Secret: <secret>" \
  -d '{
    "content": "https://yourbrand.com",
    "prompt": "art deco gold leaf, geometric chevrons, ivory background",
    "llmProvider": "openai",
    "llmApiKey": "sk-...",
    "creativity": 0.6,
    "strictScannability": true,
    "stylePreset": "luxury"
  }'

LLM 凭据由你提供。引擎会验证生成的配置,执行扫描保证检查,然后渲染二维码。

市场:托管 AI,无需 LLM 密钥

curl -X POST https://api.qr-branding.com/api/qr/ai/generate-managed \
  -H "Content-Type: application/json" \
  -H "X-RapidAPI-Proxy-Secret: <secret>" \
  -d '{
    "content": "https://yourbrand.com",
    "prompt": "art deco gold leaf, geometric chevrons, ivory background",
    "creativity": 0.6,
    "strictScannability": true,
    "stylePreset": "luxury"
  }'

无需 llmProvider / llmApiKey。服务器使用自有模型,并按 Groq → Gemini → OpenAI 的回退链依次尝试。响应包含 "managed": true,该调用计入你套餐的托管 AI 配额。

消费者:服务器端 LLM 密钥

POST https://qr-branding.com/api/qr/ai/generate/server

curl -X POST https://qr-branding.com/api/qr/ai/generate/server \
  -H "Content-Type: application/json" \
  -d '{
    "content": "https://yourbrand.com",
    "prompt": "art deco gold leaf, geometric chevrons, ivory background",
    "stylePreset": "luxury",
    "creativity": 0.6
  }'

无需 llmProvider / llmApiKey。服务器依次尝试 Groq(先 gpt-oss-120b,再 gpt-oss-20b)→ OpenAI → Gemini。成功时从你的余额中扣除 1 个 AI 额度;失败时不消耗额度。

代码示例

请求体

字段类型默认值说明
contentstring必填要编码的内容(URL / 文本)。
promptstring必填自然语言描述,≤ 10000 个字符。
stylePresetstringluxuryminimal artistic corporate playful luxury tech nature 之一。
creativitynumber0.50–1。影响 LLM 的 temperature 以及设计选择的大胆程度。
strictScannabilitybooleantrue开启时,引擎会自动修正所有可扫描性问题;关闭时只发出警告。
logoUrlstring—嵌入中心,清除其下方的模块,并将 ECC 提高到 H。
logoBase64string—同上,但以内联 base64 方式提供。
backgroundImageUrlstring—柔和的背景图片(与二维码背后融合)。
centerTextobject—{ text, color?, backgroundColor?, fontSize? }。横跨二维码的横幅。
ctaTextstring—下方的说明文字。
fileFormatstringpngpng jpg svg pdf webp。
outputWidthnumber800像素。
responseTypestringbase64base64 或 binary。

市场端点还需要提供:

字段类型说明
llmProviderstringopenai anthropic google mistral cohere groq xai deepseek qwen local
llmApiKeystring你的提供商密钥
llmModelstring可选,默认使用该提供商的默认模型(参见 /api/qr/ai/providers);接受提供商提供的任意模型 ID

响应

{
  "success": true,
  "qrBase64": "iVBORw0KGgo…",
  "format": "png",
  "contentType": "image/png",
  "sizeBytes": 38291,
  "generatedConfig": { "moduleShape": "diamond", "finderOuterShape": "octagon", "...": "..." },
  "aiExplanation": "Diamond modules and octagonal finders for the geometric art deco feel; gold-on-ivory keeps contrast at 6.4:1.",
  "llmProviderUsed": "openai",
  "llmModelUsed": "gpt-6-luna"
}

generatedConfig 是 AI 生成的完整 QrConfig。如果你想把这份配置带到手动模式中手动微调,它会很有用。

另请参阅