external-api

A rule set for connecting an application to outside services through API clients and environment-based configuration. It describes how credentials reach a service and how an unconfigured integration should behave.

In plain words
What is it for?
Use it when adding or changing an external API, webhook, template ID, API key, timeout, service wrapper, or related configuration.
Why use it?
It keeps API keys and other secrets out of source code and makes missing configuration fail cleanly instead of causing crashes. It also gives integrations a consistent structure.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/golid-ai/golid/external-api
Clone the repo
git clone --depth 1 https://github.com/golid-ai/golid

Made for: Cursor.

Per session 0 Nothing until a file matches its globs; then the whole rule loads.
When invoked 604 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.00604
Opus 5 $0.00000 $0.00302
Sonnet 5 $0.00000 $0.00121
Haiku 4.5 $0.00000 $0.00060

Measured 2d ago against content hash 591f2687ef8a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

external-api scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/external-api.mdc · 68 lines

How it starts

The opening of the file, as written. The whole thing — 68 lines — stays where its author put it; the contents beside it link to each section on GitHub.

External API Integration Patterns

Thesis: External services are wrapped with IsConfigured(), env-sourced credentials, and graceful degradation when unconfigured.

Service Wrapper Structure

type XService struct {
    apiKey     string
    configured bool
    client     *http.Client
}

func NewXService(apiKey string) *XService {
    if apiKey == "" {
        slog.Warn("X not configured — feature will be disabled")
        return &XService{configured: false}
    }
    return &XService{apiKey: apiKey, configured: true, client: &http.Client{Timeout: 30 * time.Second}}
}

func (s *XService) IsConfigured() bool { return s.configured }

Every method must check IsConfigured() first and return a clean error, not panic.

Config Flow

API keys and secrets flow: env var → Config struct → service constructor → wire.BuildServices.

.env.local:       EXTERNAL_API_KEY=xxx
config.go:        ExternalAPIKey string → os.Getenv("EXTERNAL_API_KEY")
wire/services.go: externalService := external.NewExternalService(cfg.ExternalAPIKey)

Template IDs, webhook secrets, and other per-service config follow the same pattern. Never hardcode in service files.

Request Building

  • Verify field names against the actual API docs. JSON struct tags must match exactly (e.g., roleIndex not role_index).
  • Query params vs body — some APIs put IDs in the URL, not the body. Check the docs.
  • URL-encode all query parameter values with url.QueryEscape().
  • Set timeouts on the HTTP client (30s default).
  • Close response bodies with defer resp.Body.Close().

Webhook Handling

  • Verify signatures — HMAC-SHA256 with timing-safe hmac.Equal. Read raw body with io.ReadAll before parsing.
  • Return 200 on parse errors — prevents the external service from retrying malformed events indefinitely.
  • Return 500 on handler errors — signals the external service to retry.
  • Register on public route group — webhooks don't have JWT auth, they use their own signature verification.
  • Exclude from gzip middleware — webhook bodies need to be read raw for signature verification.

Read the full file on GitHub · 68 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 68 lines · 0 tokens per session scan A 591f2687ef8a

Subscribe to this mod's changes

external-api is a cursor rule published in the GitHub repository golid-ai/golid (40 stars, last pushed 2mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 604 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.