Stripe Api Style logo

Stripe Api Style

Community
happydog-intj
stripe-api-style

Stripe API 设计风格 Skill。蒸馏自 Stripe API 文档、Stripe Engineering Blog、 SDK 源码(stripe-python/stripe-node)、Patrick Collison 的 API 设计原则、 Stripe 工程师的技术演讲。 触发词:「Stripe 风格」「像 Stripe 一样设计 API」「stripe style」「REST API 最佳实践」。 适用:REST API 设计、SDK 开发、支付/金融系统 API、开发者体验设计。

Overview

Publisherhappydog-intj
Repositoryluban-skill
Skill namestripe-api-style
Stars
32
Forks
3
Bundled files
Instructions only
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • Self-contained

    Everything the model needs lives in the instructions — no extra files to sync.

  • Open source

    Published by happydog-intj on GitHub. Read the source before you install it.

Installation

Install the Stripe Api Style AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/happydog-intj/luban-skill/tree/master/skills/stripe-api.skill
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/happydog-intj/luban-skill.git /tmp/luban-skill
mkdir -p .claude/skills
cp -r /tmp/luban-skill/skills/stripe-api.skill .claude/skills/stripe-api-style
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Stripe Api Style in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Stripe Api Style on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Stripe Api Style is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Stripe API · 设计 DNA

"An API is a product. Its users are developers. Their experience matters." — Stripe Engineering

角色定义

此 Skill 激活后,你设计的 API 和 SDK 应该让开发者看 5 分钟文档就能上手, 而不是翻 3 天 StackOverflow。

Stripe 是 API 设计的行业标杆。 不是因为功能最多,而是因为每个细节都替开发者想到了。

这意味着:可预测、容错、开发者优先。


URL 设计 DNA

4 条直觉规则:

  1. 资源用复数名词,动作用 URL 后缀

    # ✅ Stripe 风格
    POST   /v1/payment_intents              # 创建
    GET    /v1/payment_intents/{id}         # 获取
    POST   /v1/payment_intents/{id}/confirm # 动作(不用 PUT/PATCH 做动作)
    POST   /v1/payment_intents/{id}/cancel  # 动作
    
    # ❌ 常见错误
    POST   /v1/createPaymentIntent          # 动词在 URL 里
    PUT    /v1/payment_intents/{id}/status  # 用 HTTP 方法表达动作
  2. 嵌套资源最多一层

    # ✅
    GET /v1/customers/{customer_id}/sources
    
    # ❌ 嵌套过深,URL 复杂化
    GET /v1/customers/{id}/subscriptions/{sub_id}/items/{item_id}/discounts
  3. 资源 ID 带类型前缀,全局唯一

    pi_3MtwBwLkdIwHu7ix28a3tqPa   # PaymentIntent
    cus_NffrFeUfNV2Hib             # Customer
    ch_3MmlLrLkdIwHu7ix0snN0B15   # Charge

    这样通过 ID 就能知道是什么资源,debug 时省大力气。

  4. 版本在 URL 里,不在 header 里

    # ✅ Stripe 风格 — 版本可见、可分享、可 bookmark
    GET /v1/charges
    
    # ❌ header 版本 — 不直觉,容易被代理丢掉
    GET /charges
    API-Version: 2024-04-10

请求/响应设计

请求:

http
POST /v1/payment_intents
Content-Type: application/x-www-form-urlencoded   # Stripe 用 form encoding,不是 JSON
Authorization: Bearer sk_test_...

amount=2000&currency=usd&payment_method=pm_xxx&confirm=true
  • 用 form encoding(历史选择,但 Stripe 坚持保持一致性)
  • 所有金额用最小货币单位(分),避免浮点数问题

响应结构(永远一致):

json
{
  "id": "pi_3MtwBwLkdIwHu7ix28a3tqPa",
  "object": "payment_intent",      // 类型标识,永远有
  "amount": 2000,
  "currency": "usd",
  "status": "succeeded",
  "created": 1679090702,           // Unix timestamp,不是 ISO 8601
  "livemode": false,               // 测试/生产环境标识
  "metadata": {}                   // 用户自定义字段,永远有
}

object 字段是 Stripe 的杀手锏:

  • 任何响应都有 object 字段标识类型
  • Webhook、列表、嵌套对象统统如此
  • 开发者不需要靠 URL 或 context 猜类型

错误处理设计

Stripe 的错误设计是业界范本:

json
{
  "error": {
    "type": "card_error",              // 错误大类
    "code": "card_declined",           // 机器可读的具体代码
    "decline_code": "insufficient_funds",  // 更细的子代码
    "message": "Your card has insufficient funds.",  // 人可读消息
    "param": "card",                   // 哪个参数引起的
    "doc_url": "https://stripe.com/docs/error-codes/card-declined"  // 文档链接!
  }
}

5 条错误设计规则:

  1. 错误类型分层: type(大类)→ code(具体)→ decline_code(支付特有)
  2. HTTP 状态码语义化:
    • 400 — 参数错误(你的锅)
    • 401 — 认证失败
    • 402 — 支付失败(Stripe 特有)
    • 404 — 资源不存在
    • 429 — 限流
    • 500 — 我们的锅
  3. 永远提供 doc_url — 让开发者能自助
  4. param 字段 — 指出是哪个参数的问题,不让开发者猜
  5. 错误消息面向用户,不面向开发者 — message 可以直接展示给终端用户

SDK 设计哲学

Stripe SDK 的设计原则(以 Python 为例):

python
# ✅ Stripe SDK 风格:资源.动作(),链式直觉
import stripe

# 简单操作
intent = stripe.PaymentIntent.create(
    amount=2000,
    currency="usd",
)

# 更新
intent = stripe.PaymentIntent.modify(
    "pi_xxx",
    metadata={"order_id": "6735"},
)

# 动作
intent = stripe.PaymentIntent.confirm("pi_xxx")

# 分页:自动处理,不暴露 cursor 细节
for customer in stripe.Customer.auto_paging_iter():
    process(customer)

SDK 设计要点:

  • 每个 API 资源对应一个 SDK class(stripe.PaymentIntent、stripe.Customer)
  • 类方法映射 HTTP 方法:create → POST,retrieve → GET,modify → POST 更新,list → GET list
  • 自动重试(指数退避)对 5xx 和网络错误
  • Stripe-Idempotency-Key 自动处理,POST 请求可重试
  • 分页自动处理,auto_paging_iter() 透明迭代

幂等性设计

Stripe 的幂等键是工程杰作:

http
POST /v1/payment_intents
Idempotency-Key: a0d92f5c-e5c0-4d3d-b5b3-7a1c9f8c6b2e

amount=2000&currency=usd
  • 同一个 key 在 24 小时内重复请求,返回同一个结果
  • 网络超时后可以安全重试,不会重复扣款
  • SDK 自动生成并附加幂等键(对开发者透明)

自己的 API 设计规则:

  • 所有创建资源的操作必须支持幂等键
  • 幂等键放 HTTP header,不放 body(避免 body 内容不一致时的歧义)
  • 存储层面:key + 请求 hash → 缓存响应

Webhook 设计

json
{
  "id": "evt_3MtwBwLkdIwHu7ix2sRetfHb",
  "object": "event",
  "type": "payment_intent.succeeded",    // 资源.事件,点分隔
  "created": 1679090712,
  "livemode": false,
  "data": {
    "object": { /* 完整的 PaymentIntent 对象 */ }
  },
  "api_version": "2023-10-16"            // 快照时的 API 版本
}

Webhook 5 大原则:

  1. type 格式:{resource}.{event}(payment_intent.succeeded)
  2. data.object 包含完整资源快照,不需要再调 API 查
  3. 总是包含 api_version,subscriber 知道 payload 格式
  4. 签名验证:Stripe-Signature header + 时间窗口防重放
  5. 重试:指数退避,最多 3 天

反模式(绝不这样写)

  1. URL 里放动词

    POST /api/createOrder        # ❌
    POST /api/orders             # ✅
  2. 浮点数表示金额

    json
    { "amount": 19.99 }   // ❌ 精度噩梦
    { "amount": 1999 }    // ✅ 最小单位(分)
  3. 没有 object 类型字段 — 无法区分不同资源的响应

  4. 错误只有 HTTP 状态码 — 机器无法理解具体原因

  5. 分页用 offset/page — 数据变化时分页结果不稳定,用 cursor

    # ❌
    GET /orders?page=2&per_page=10
    
    # ✅ cursor 分页,稳定
    GET /orders?starting_after=ord_xxx&limit=10
  6. 破坏性变更不版本化 — 字段重命名必须引入新版本

  7. Webhook payload 不含完整对象 — 不要只发 ID,让用户再查一次


校验测试

  1. 5 分钟测试:给一个没见过这个 API 的开发者,5 分钟内能成功调通第一个请求吗?
  2. 重试测试:同一个 POST 请求发两次,结果一致吗?资源只创建了一次吗?
  3. 错误测试:传一个错误参数,错误消息能告诉开发者具体哪里错了、怎么修吗?

来源

Frequently asked questions

What does the Stripe Api Style AI skill do?

Stripe API 设计风格 Skill。蒸馏自 Stripe API 文档、Stripe Engineering Blog、 SDK 源码(stripe-python/stripe-node)、Patrick Collison 的 API 设计原则、 Stripe 工程师的技术演讲。 触发词:「Stripe 风格」「像 Stripe 一样设计 API」「stripe style」「REST API 最佳实践」。 适用:REST API 设计、SDK 开发、支付/金融系统 API、开发者体验设计。

Why use Stripe Api Style on TypingMind?

Because you install it once and use it with any model. Stripe Api Style is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Stripe Api Style in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/happydog-intj/luban-skill/tree/master/skills/stripe-api.skill. TypingMind reads its SKILL.md and installs it as a skill you can enable per chat.

Which AI models can use Stripe Api Style?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Stripe Api Style?

As many as you like. As long as a model supports skills, you can use Stripe Api Style with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Stripe Api Style AI skill free?

It is published on GitHub by happydog-intj. Check the repository for licensing terms. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇