context

A reference document describing the architecture and public interface of a Rails engine named rails_api_keys. Rails is a Ruby web framework, and an engine is a reusable component that plugs into a Rails application.

In plain words
What is it for?
Use it when building or changing personal API-key creation and authentication for Rails applications, including which models may own keys and how keys are configured.
Why use it?
It keeps the engine's naming, data model, configuration, and supported behavior in one agreed source of truth.

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/rubyroidlabs/rails_api_keys/context
Clone the repo
git clone --depth 1 https://github.com/rubyroidlabs/rails_api_keys

Made for: Cursor.

Per session 727 This file is loaded in full into every session.
When invoked 727 The same file — it is already loaded in full.
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.00727 $0.00727
Opus 5 $0.00364 $0.00364
Sonnet 5 $0.00145 $0.00145
Haiku 4.5 $0.00073 $0.00073

Measured yesterday against content hash 68efa394df7c, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

context 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 yesterday.

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/context.mdc · 97 lines

How it starts

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

rails_api_keys Context

Single source of truth for engine state and architecture

Overview

Reusable Rails engine that issues and authenticates personal API keys. Intentionally thin: keys + auth helpers only. Public MIT-licensed gem.

Naming

  • Gem / require / repo: rails_api_keys
  • Module: RailsApiKeys
  • Table: rails_api_keys_api_keys
  • Generator: rails_api_keys:install

Technology

  • Rails engine (>= 7.0), isolated namespace RailsApiKeys
  • Active Record for rails_api_keys_api_keys
  • No frontend, mailers, jobs, or mounted business routes

Public surface

has_api_keys (on owner models)

  • Declares polymorphic has_many :api_keys and registers the model as an allowed owner
  • Adds create_api_key!(name:, permission:)[record, raw_token] (wraps ApiKey.generate_for!)
  • Multiple models may opt in (e.g. User, Company)
  • Models without the macro cannot own keys

Configuration (RailsApiKeys.configure) — all optional

Option Default Purpose
token_prefix nil"#{AppName.downcase}_ak_" Prefix for generated raw tokens
owner_active uses active_for_authentication? when present Gate authenticate on owner liveness

Host initializers should only set overrides; do not restate defaults.

RailsApiKeys::ApiKey

  • Polymorphic belongs_to :owner
  • Permissions: read, read_write (immutable after create)
  • generate_for!(owner:, name:, permission:)[record, raw_token]
  • authenticate(raw_token) → active key if digest matches and owner active; touches last_used_at
  • revoke! sets revoked_at
  • Stores token_digest (SHA-256), token_display_prefix; never plaintext

RailsApiKeys::Authentication

  • authenticate_api_key! — Bearer token → current_api_key / current_api_owner; 401 on auth failure; GET/HEAD require read, other methods require write (403 if lacking)

Install

bin/rails generate rails_api_keys:install
bin/rails db:migrate

Read the full file on GitHub · 97 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. yesterday First seen · 97 lines · 727 tokens per session scan A 68efa394df7c

Subscribe to this mod's changes

context is a cursor rule published in the GitHub repository rubyroidlabs/rails_api_keys (10 stars, last pushed 15d ago), licensed MIT. It adds 727 tokens to every session, about $0.0036 per session on Opus 5. 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-31.