OpenCoze
Back to template library

GitHub PR Automation: Keep API Token Usage in Check

DevelopmentCozeUpdated 2026-05-08

Automatically analyze PR diffs, generate concise feedback, and skip heavy analysis when token usage exceeds a set threshold to control costs.

System Prompt
When PR {pr_number} is created in repository {repo_name}, trigger this workflow.
1. Use GitHub API to fetch PR diff.
2. Estimate token usage based on diff lines.
3. If estimated tokens > {token_limit}, post a comment "Deep analysis skipped, token limit reached." and exit.
4. Otherwise, call OpenAI to generate detailed review and comment.
5. Log actual token usage.

Variable Dictionary (fill in your AI tool)

This section only explains placeholders. It is not an input form on this website. Copy the prompt, then replace variables in Coze / Dify / ChatGPT.

{repo_name}

Full GitHub repo name, e.g., "org/repo"

Filling hint: replace this with your real business context.

{pr_number}

Pull request number

Filling hint: replace this with your real business context.

{token_limit}

Maximum allowed token usage (integer)

Filling hint: replace this with your real business context.

Quick Variable Filler (Optional)

Fill variables below to generate a ready-to-run prompt in your browser.

{repo_name}

Full GitHub repo name, e.g., "org/repo"

{pr_number}

Pull request number

{token_limit}

Maximum allowed token usage (integer)

Generated Prompt Preview

Missing: 3
When PR {pr_number} is created in repository {repo_name}, trigger this workflow.
1. Use GitHub API to fetch PR diff.
2. Estimate token usage based on diff lines.
3. If estimated tokens > {token_limit}, post a comment "Deep analysis skipped, token limit reached." and exit.
4. Otherwise, call OpenAI to generate detailed review and comment.
5. Log actual token usage.

How to Use This Template

Best for

Teams that need faster development output with more stable prompt quality.

Problem it solves

Reduces blank-page time, missing constraints, and inconsistent output structure from ad-hoc prompting.

Steps

  1. Copy the template prompt.
  2. Paste it into your AI tool (Coze / Dify / ChatGPT).
  3. Replace placeholder variables using the dictionary above.
  4. Run and refine constraints based on output quality.

Not ideal when

You need live web retrieval, database writes, or multi-step tool orchestration. Use full workflow automation for that.

Success Case

Input:
repo_name: "org/example", pr_number: 42, token_limit: 2000
Output:
Comment: "Generated detailed review, used 1,800 tokens."

Boundary Case

Input:
repo_name: "org/example", pr_number: 99, token_limit: 500
Fix:
Increase token_limit or optimize review template to reduce token consumption.

What to Try Next

Keep exploring with similar templates and matching tools.

Continue Where You Left Off

No recent items yet.

Workflow Steps

  1. 1. Listen for PR creation and extract {repo_name} and {pr_number}

  2. 2. Call GitHub API to get diff and count added/removed lines

  3. 3. Estimate tokens (lines × 0.5)

  4. 4. If estimate > {token_limit}, comment with summary template and stop; else call OpenAI for full review and comment

  5. 5. Record actual token usage to log or monitoring

Constraints

  • Diffs over 10,000 lines automatically skip deep analysis
  • Private repos require access token

Explore More in This Category

Development

Recommended Stack

Tools that work well with this template.

Coze

Official site

Low-code agent workflow platform for fast automation delivery.

Open

OpenAI

Official site

General LLM platform for generation, analysis, and development use cases.

Open