Agent Skills › pollinations/pollinations › bring-your-own-pollen

bring-your-own-pollen

GitHub

实现 BYOP 功能,让用户通过授权支付 Pollen。支持 OAuth、Fragment 及 Device 等多种认证流程,生成 scoped sk_ key,确保用户掌控预算且开发者可获利。

.claude/skills/bring-your-own-pollen/SKILL.md pollinations/pollinations

触发场景

需要集成用户付费认证 选择 OAuth、Fragment 或 Device 认证流 构建需用户授权 sk_ key 的 App 或 CLI

安装

npx skills add pollinations/pollinations --skill bring-your-own-pollen -g -y
更多选项

非标准路径

npx skills add https://github.com/pollinations/pollinations/tree/main/.claude/skills/bring-your-own-pollen -g -y

不安装直接使用

npx skills use pollinations/pollinations@bring-your-own-pollen

指定 Agent (Claude Code)

npx skills add pollinations/pollinations --skill bring-your-own-pollen -a claude-code -g -y

安装 repo 全部 skill

npx skills add pollinations/pollinations --all -g -y

预览 repo 内 skill

npx skills add pollinations/pollinations --list

SKILL.md

Frontmatter
{
    "name": "bring-your-own-pollen",
    "description": "Add Bring Your Own Pollen (BYOP) sign-in to an app so each user pays with their own Pollen instead of the app's key. Use when building an app, CLI, extension or agent tool on Pollinations and you need the user-authorized sk_ key, when you must choose between the OAuth code flow, the fragment flow and the device flow, or when an app key's usage must be attributed and monetized."
}

bring-your-own-pollen — user-paid Pollinations apps

BYOP lets your users authorize your app to spend their Pollen. The app sends users to the consent screen with a publishable App Key (pk_...) and gets back a scoped user key (sk_...) for generation calls. The app owner never pays for user usage, and users keep control of budget, expiry and revocation.

Full reference: https://gen.pollinations.ai/docs/llm.txt?section=byop and https://enter.pollinations.ai/.well-known/oauth-authorization-server.

Pick the flow first

Your app Flow Who exchanges the code
Web app with a backend OAuth authorization-code + PKCE Backend (keeps secret)
Static / browser-only web app OAuth authorization-code + PKCE Browser via fetch (PKCE replaces the secret)
Legacy web app Fragment redirect No exchange; key arrives in #api_key=
CLI, bot, extension, anything headless Device flow The app polls the token endpoint

If you are unsure, default to the OAuth code flow with PKCE for new web work; it keeps sk_... out of the browser callback URL.

Step 1 — App Key (client_id)

Create one at https://enter.pollinations.ai/keys → Create New App Key, or via the API:

curl -X POST https://gen.pollinations.ai/account/keys \
  -H 'Authorization: Bearer sk_yoursecretkey' \
  -H 'Content-Type: application/json' \
  -d '{"name":"my-app","type":"publishable","redirectUris":["https://myapp.com/callback"],"earningsEnabled":true}'
  • redirectUris must match the callback exactly, query string included. Loopback http://localhost matches any port.
  • earningsEnabled: true opts into developer earnings: users pay 25% over base rates and the markup credits your balance, in the same bucket the user paid from.

Step 2 — OAuth code flow with PKCE

Build the auth link (generate a fresh verifier per attempt):

https://enter.pollinations.ai/authorize
  ?response_type=code
  &client_id=pk_yourkey
  &redirect_uri=https://myapp.com/callback
  &scope=profile%20usage
  &state=random-csrf-token
  &code_challenge=BASE64URL_SHA256_VERIFIER
  &code_challenge_method=S256

Optional restrictions: models=image,text (or individual IDs), budget=10 (Pollen cap, default 5), expiry=7 (days, default 7). The user can narrow these on the consent screen.

Handle the callback — validate state, then exchange the single-use code (10-minute TTL):

curl -X POST https://enter.pollinations.ai/api/oauth/token \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=authorization_code' \
  -d 'code=oauth_code' \
  -d 'client_id=pk_yourkey' \
  -d 'redirect_uri=https://myapp.com/callback' \
  -d 'code_verifier=YOUR_PKCE_VERIFIER'
# -> { "access_token": "sk_...", "token_type": "bearer", "expires_in": 604800, "scope": "profile usage" }

There are no refresh tokens — re-run the flow when the key expires. Store the token in memory or sessionStorage; never in localStorage, a URL, analytics or logs.

Step 3 — Call the API with the user key

await fetch('https://gen.pollinations.ai/v1/chat/completions', {
  method: 'POST',
  headers: { Authorization: `Bearer ${accessToken}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({ model: 'openai/gpt-5.4-nano', messages: [{ role: 'user', content: 'yo' }] }),
});

Generation needs no scope — spending is bounded by the budget and expiry the user approved. Scopes gate account data only: profile (name + email), usage (balance + usage), keys (create/list/revoke keys).

Device flow — the headless path

Use this for CLIs, bots and extensions that cannot show the consent page.

# 1. request a device code (pass client_id for attribution)
curl -X POST https://enter.pollinations.ai/api/device/code \
  -H 'Content-Type: application/json' \
  -d '{"client_id": "pk_yourkey"}'
# -> { "device_code": "...", "user_code": "ABCD-1234",
#      "verification_uri": "https://enter.pollinations.ai/device",
#      "verification_uri_complete": "https://enter.pollinations.ai/device?user_code=ABCD-1234",
#      "expires_in": 1800, "interval": 5 }

# 2. show verification_uri_complete to the user, then poll every `interval` seconds
curl -X POST https://enter.pollinations.ai/api/device/token \
  -H 'Content-Type: application/json' \
  -d '{"device_code": "..."}'
# pending -> { "error": "authorization_pending" }
# done    -> { "access_token": "sk_...", "token_type": "bearer" }

The same exchange is available at the standard endpoint with grant_type=urn:ietf:params:oauth:grant-type:device_code.

Fragment flow (legacy web)

https://enter.pollinations.ai/authorize?redirect_uri=https://myapp.com/callback&client_id=pk_yourkey&scope=usage

The key returns in the URL fragment (#api_key=sk_...&state=...), so it never hits server logs. On denial the fragment is #error=access_denied.

const apiKey = new URLSearchParams(location.hash.slice(1)).get('api_key');

Identify the key holder

curl https://enter.pollinations.ai/api/device/userinfo \
  -H 'Authorization: Bearer sk_...'
# -> { "sub": "user-id", "preferred_username": "voodoohop", "picture": "..." }
# with `profile` scope: also "name", "email"

Checklist

  • App Key created with the exact redirect_uri and earningsEnabled if you monetize.
  • Fresh PKCE verifier + S256 challenge per attempt.
  • state validated on the callback.
  • Token kept in memory/sessionStorage; expiry handled by re-running the flow.
  • Device flow used for headless apps, polling at the returned interval.

版本历史

  • 5cb4f4b 当前 2026-10-19 13:07

同 Skill 集合

.agents/skills/pollinations-sdk/SKILL.md
.claude/skills/abuse-detection/SKILL.md
.claude/skills/candidate-evaluation/SKILL.md
.claude/skills/code-formatting/SKILL.md
.claude/skills/community-leaderboard/SKILL.md
.claude/skills/economics-provider-collection/SKILL.md
.claude/skills/enter-services/SKILL.md
.claude/skills/grilling/SKILL.md
.claude/skills/issue-maker/SKILL.md
.claude/skills/manage-vast-gpu-fleet/SKILL.md
.claude/skills/model-debugging/SKILL.md
.claude/skills/model-management/SKILL.md
.claude/skills/monitor-services/SKILL.md
.claude/skills/news-pipeline/SKILL.md
.claude/skills/polli-video/SKILL.md
.claude/skills/polli/SKILL.md
.claude/skills/pollinations-api/SKILL.md
.claude/skills/pollinations-sdk/SKILL.md
.claude/skills/pollinations-support-triage/SKILL.md
.claude/skills/quest-contributor/SKILL.md
.claude/skills/quest-solution-review/SKILL.md
.claude/skills/r2-glacier-migration/SKILL.md
.claude/skills/spending-analysis/SKILL.md
.claude/skills/sync-production/SKILL.md
.claude/skills/tinybird-deploy/SKILL.md
.claude/skills/voting-status/SKILL.md
.claude/skills/web-research/SKILL.md
apps/openclaw/skills/founder-meditation/SKILL.md
packages/polli-cli/SKILL.md
.agents/skills/ponytail/SKILL.md
.claude/skills/ponytail/SKILL.md
.agents/skills/source-command-review/SKILL.md
.claude/skills/grill-me/SKILL.md

元信息

文件数
0
版本
5cb4f4b
Hash
e04798cd
收录时间
2026-10-19 13:07

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-19 20:00
浙ICP备14020137号-1