capit 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
capit-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,305 @@
1
+ Metadata-Version: 2.4
2
+ Name: capit
3
+ Version: 0.1.0
4
+ Summary: Issue authentication keys with spending caps
5
+ Author: capit contributors
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/capit/capit
8
+ Project-URL: Repository, https://github.com/capit/capit
9
+ Keywords: api,keys,authentication,spending-limits,cli
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: MIT License
14
+ Classifier: Operating System :: OS Independent
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.8
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Security
22
+ Classifier: Topic :: Utilities
23
+ Requires-Python: >=3.8
24
+ Description-Content-Type: text/markdown
25
+ Requires-Dist: click>=8.0.0
26
+ Requires-Dist: requests>=2.28.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
29
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
30
+
31
+ <p align="center">
32
+ <img width="500" height="187" alt="capit_500" src="https://github.com/user-attachments/assets/db22c959-ffee-4540-9108-2928e9c73f70" />
33
+ <br/><strong>Buget per-agent, per-provider, as little or as much as you want</strong>
34
+ </p>
35
+
36
+ ```bash
37
+ $ capit openrouter 5.00 --agent openclaw
38
+ $5.00 openrouter key installed into openclaw
39
+ ```
40
+
41
+ That's it. You now have an API key with a **$5/month spending cap** enforced by OpenRouter installed into openclaw's setting file. If it goes rogue, it can only spend $5.
42
+
43
+ ## The Problem
44
+
45
+ You want to use AI agents but you don't trust them with unlimited access to your credit card:
46
+
47
+ - Claude Code might get stuck in a loop
48
+ - Cursor might burn through tokens debugging
49
+ - Your custom agent might have a bug
50
+ - You want to try multiple agents without risk
51
+
52
+ Traditional secrets management is overkill. You just want a **spending limit**.
53
+
54
+ ## The Solution
55
+
56
+ capit creates **limited API keys** with spending caps enforced by the provider:
57
+
58
+ ```bash
59
+ # Give Claude Code a $5/month cap
60
+ capit openrouter 5.00 --agent claude
61
+
62
+ # Give Cursor a $10/month cap
63
+ capit openrouter 10.00 --agent cursor
64
+
65
+ # Give your custom agent a $1/month cap
66
+ capit openrouter 1.00
67
+ ```
68
+
69
+ ## Quick Start
70
+
71
+ ### Install
72
+
73
+ ```bash
74
+ pip install capit
75
+ ```
76
+
77
+ ### Issue a limited key
78
+
79
+ ```bash
80
+ # Basic: $1/month cap
81
+ capit openrouter 1.00
82
+
83
+ # Named key for organization
84
+ capit openrouter 5.00 --name claude --prefix prod
85
+
86
+ # Send directly to your agent (auto-configures + auto-names the key)
87
+ capit openrouter 5.00 --agent claude
88
+
89
+ # Skip confirmation prompt
90
+ capit openrouter 5.00 --agent claude -y
91
+ ```
92
+
93
+ ### First time? No setup friction
94
+
95
+ ```bash
96
+ $ capit openrouter 5.00 -i
97
+ No master key found for 'openrouter'.
98
+ Enter your management API key (won't be stored):
99
+ Key: sk-or-v1-management-...
100
+ sk-or-v1-limited-key-...
101
+ ```
102
+
103
+ The `-i` flag prompts for your management key once, uses it to create the limited key, and discards it. Perfect for trying it out.
104
+
105
+ ## Consumers
106
+
107
+ "Consumers" are AI agents and tools that use API keys. capit sends capped keys directly to them:
108
+
109
+ ```bash
110
+ # List available consumers
111
+ capit --consumers
112
+ # claude
113
+ # cursor
114
+ # windsurf
115
+ # example
116
+
117
+ # Send to a consumer
118
+ capit openrouter 5.00 --agent claude
119
+ ```
120
+
121
+ ### Built-in consumers
122
+
123
+ | Consumer | Command |
124
+ |----------|---------|
125
+ | Claude / Claude Code | `capit openrouter 5.00 --agent claude` |
126
+ | Cursor IDE | `capit openrouter 10.00 --agent cursor` |
127
+ | Windsurf | `capit openrouter 5.00 --agent windsurf` |
128
+
129
+ ### Example: Claude Code
130
+
131
+ ```bash
132
+ # Create a $5/month capped key and get instructions
133
+ $ capit openrouter 5.00 --agent claude
134
+
135
+ 🔑 Generated limited key for openrouter ($5.00 cap)
136
+ Key: sk-or-v1-...
137
+
138
+ To use with Claude, run:
139
+ export OPENROUTER_API_KEY=sk-or-v1-...
140
+
141
+ Or pipe to claude-code:
142
+ OPENROUTER_API_KEY=sk-or-v1-... claude
143
+ ```
144
+
145
+ Now Claude can only spend $5/month. Sleep soundly.
146
+
147
+ ### Add your own consumer
148
+
149
+ Consumers live in `capit/consumers/`. To add one:
150
+
151
+ ```bash
152
+ # Copy the template
153
+ cp capit/consumers/example.py capit/consumers/myagent.py
154
+
155
+ # Edit it to customize for your tool
156
+ ```
157
+
158
+ The `send()` function in your consumer file gets called with the key and should output instructions or configure your tool. See [new-platform.md](new-platform.md) for details.
159
+
160
+ ## For Agent Authors
161
+
162
+ If you're building an AI agent, make it a **consumer**:
163
+
164
+ ### Option 1: Document the command
165
+
166
+ Tell users to run:
167
+ ```bash
168
+ capit openrouter 5.00 --agent your-agent
169
+ ```
170
+
171
+ ### Option 2: Integrate directly
172
+
173
+ Add a handler in your setup script:
174
+
175
+ ```python
176
+ # In your agent's install/setup script
177
+ import subprocess
178
+
179
+ def setup_api_key():
180
+ result = subprocess.run(
181
+ ["capit", "openrouter", "5.00", "--agent", "your-agent"],
182
+ capture_output=True,
183
+ text=True
184
+ )
185
+ # Parse the key from output and configure
186
+ ```
187
+
188
+ ### Option 3: Create a custom consumer
189
+
190
+ Add your handler to capit (or fork and customize):
191
+
192
+ ```python
193
+ def send_to_youragent(key, platform, spend_cap):
194
+ click.echo(f"\n🔑 Limited key for {platform} (${spend_cap} cap)")
195
+ click.echo(f"Key: {key}")
196
+ click.echo(f"\nAdd to ~/.youragent/config:")
197
+ click.echo(f" api_key: {key}")
198
+ # Or write directly to config file
199
+ return key
200
+ ```
201
+
202
+ ## Administration
203
+
204
+ All admin commands use `--` prefix (Unix style):
205
+
206
+ ```bash
207
+ # List your stored master keys
208
+ capit --keys list
209
+
210
+ # Add a master key (stored locally for future use)
211
+ capit --keys add openrouter
212
+
213
+ # List actual API keys created on OpenRouter
214
+ capit --keys list -r openrouter
215
+ # Output:
216
+ # 4ab1e7e3ebc75228... prod-claude-abc123 $5 2026-03-19 [active]
217
+ # 5f54d6da2cdf0d47... dev-testing-def456 $1 2026-03-19 [active]
218
+
219
+ # Revoke a specific API key
220
+ capit --keys delete openrouter 4ab1e7e3ebc75228
221
+
222
+ # Remove a stored master key
223
+ capit --keys remove openrouter
224
+
225
+ # List platforms
226
+ capit --platforms
227
+
228
+ # List storage backends
229
+ capit --stores
230
+ ```
231
+
232
+ ## How It Works
233
+
234
+ 1. You run `capit openrouter 5.00`
235
+ 2. capit calls OpenRouter's Management API
236
+ 3. capit creates a **guardrail** with $5/month budget limit
237
+ 4. capit creates an **API key** with that guardrail attached
238
+ 5. You get back a limited key: `sk-or-v1-...`
239
+
240
+ The spending cap is **enforced by OpenRouter**, not just locally tracked. The key literally cannot spend more than the cap.
241
+
242
+ ## Platforms
243
+
244
+ capit works with multiple platforms:
245
+
246
+ ### OpenRouter (LLM APIs)
247
+
248
+ Creates keys with spending caps enforced by OpenRouter. Perfect for AI agents.
249
+
250
+ ```bash
251
+ capit openrouter 5.00 --agent claude
252
+ ```
253
+
254
+ ### Unkey (Rate-limited API keys)
255
+
256
+ Creates keys with rate limits and usage caps. Perfect for API access control.
257
+
258
+ ```bash
259
+ # 100 credits/month + 10 requests/minute rate limit
260
+ capit unkey 100 --name my-api --prefix prod
261
+ ```
262
+
263
+ Unkey supports:
264
+ - **Usage limits** - Cap total API calls (credits)
265
+ - **Rate limits** - Requests per second/minute/hour
266
+ - **Auto-refill** - Daily or monthly credit restoration
267
+ - **Key expiration** - Temporary keys that auto-expire
268
+
269
+ See [new-platform.md](new-platform.md) for adding more platforms.
270
+
271
+ ## Storage
272
+
273
+ Master keys are stored locally in `$HOME/.local/capit/`:
274
+ - `secrets.txt` - Your master keys (dotenv format)
275
+ - `master-lookup` - Maps platforms to storage backends
276
+
277
+ You can implement custom storage backends (YubiKey-gated, encrypted, etc.). See `capit/stores/dotenv.py` for the interface.
278
+
279
+ ## One-shot / Ephemeral Mode
280
+
281
+ Don't want to store anything? Use `-i` to enter your key once:
282
+
283
+ ```bash
284
+ capit openrouter 5.00 -i
285
+ ```
286
+
287
+ The key is used to create the limited key, then discarded. Next time you'll be prompted again. Perfect for:
288
+ - Trying capit for the first time
289
+ - CI/CD environments
290
+ - Shared machines
291
+
292
+ ## Why This Matters
293
+
294
+ AI agents are powerful but unpredictable. You should be able to:
295
+
296
+ 1. **Try new agents** without financial risk
297
+ 2. **Give different agents different budgets** (Claude gets $10, experimental agent gets $1)
298
+ 3. **Revoke access instantly** when you're done
299
+ 4. **Sleep soundly** knowing your credit card is safe
300
+
301
+ capit makes this trivial. One command. Done.
302
+
303
+ ## License
304
+
305
+ MIT
capit-0.1.0/README.md ADDED
@@ -0,0 +1,275 @@
1
+ <p align="center">
2
+ <img width="500" height="187" alt="capit_500" src="https://github.com/user-attachments/assets/db22c959-ffee-4540-9108-2928e9c73f70" />
3
+ <br/><strong>Buget per-agent, per-provider, as little or as much as you want</strong>
4
+ </p>
5
+
6
+ ```bash
7
+ $ capit openrouter 5.00 --agent openclaw
8
+ $5.00 openrouter key installed into openclaw
9
+ ```
10
+
11
+ That's it. You now have an API key with a **$5/month spending cap** enforced by OpenRouter installed into openclaw's setting file. If it goes rogue, it can only spend $5.
12
+
13
+ ## The Problem
14
+
15
+ You want to use AI agents but you don't trust them with unlimited access to your credit card:
16
+
17
+ - Claude Code might get stuck in a loop
18
+ - Cursor might burn through tokens debugging
19
+ - Your custom agent might have a bug
20
+ - You want to try multiple agents without risk
21
+
22
+ Traditional secrets management is overkill. You just want a **spending limit**.
23
+
24
+ ## The Solution
25
+
26
+ capit creates **limited API keys** with spending caps enforced by the provider:
27
+
28
+ ```bash
29
+ # Give Claude Code a $5/month cap
30
+ capit openrouter 5.00 --agent claude
31
+
32
+ # Give Cursor a $10/month cap
33
+ capit openrouter 10.00 --agent cursor
34
+
35
+ # Give your custom agent a $1/month cap
36
+ capit openrouter 1.00
37
+ ```
38
+
39
+ ## Quick Start
40
+
41
+ ### Install
42
+
43
+ ```bash
44
+ pip install capit
45
+ ```
46
+
47
+ ### Issue a limited key
48
+
49
+ ```bash
50
+ # Basic: $1/month cap
51
+ capit openrouter 1.00
52
+
53
+ # Named key for organization
54
+ capit openrouter 5.00 --name claude --prefix prod
55
+
56
+ # Send directly to your agent (auto-configures + auto-names the key)
57
+ capit openrouter 5.00 --agent claude
58
+
59
+ # Skip confirmation prompt
60
+ capit openrouter 5.00 --agent claude -y
61
+ ```
62
+
63
+ ### First time? No setup friction
64
+
65
+ ```bash
66
+ $ capit openrouter 5.00 -i
67
+ No master key found for 'openrouter'.
68
+ Enter your management API key (won't be stored):
69
+ Key: sk-or-v1-management-...
70
+ sk-or-v1-limited-key-...
71
+ ```
72
+
73
+ The `-i` flag prompts for your management key once, uses it to create the limited key, and discards it. Perfect for trying it out.
74
+
75
+ ## Consumers
76
+
77
+ "Consumers" are AI agents and tools that use API keys. capit sends capped keys directly to them:
78
+
79
+ ```bash
80
+ # List available consumers
81
+ capit --consumers
82
+ # claude
83
+ # cursor
84
+ # windsurf
85
+ # example
86
+
87
+ # Send to a consumer
88
+ capit openrouter 5.00 --agent claude
89
+ ```
90
+
91
+ ### Built-in consumers
92
+
93
+ | Consumer | Command |
94
+ |----------|---------|
95
+ | Claude / Claude Code | `capit openrouter 5.00 --agent claude` |
96
+ | Cursor IDE | `capit openrouter 10.00 --agent cursor` |
97
+ | Windsurf | `capit openrouter 5.00 --agent windsurf` |
98
+
99
+ ### Example: Claude Code
100
+
101
+ ```bash
102
+ # Create a $5/month capped key and get instructions
103
+ $ capit openrouter 5.00 --agent claude
104
+
105
+ 🔑 Generated limited key for openrouter ($5.00 cap)
106
+ Key: sk-or-v1-...
107
+
108
+ To use with Claude, run:
109
+ export OPENROUTER_API_KEY=sk-or-v1-...
110
+
111
+ Or pipe to claude-code:
112
+ OPENROUTER_API_KEY=sk-or-v1-... claude
113
+ ```
114
+
115
+ Now Claude can only spend $5/month. Sleep soundly.
116
+
117
+ ### Add your own consumer
118
+
119
+ Consumers live in `capit/consumers/`. To add one:
120
+
121
+ ```bash
122
+ # Copy the template
123
+ cp capit/consumers/example.py capit/consumers/myagent.py
124
+
125
+ # Edit it to customize for your tool
126
+ ```
127
+
128
+ The `send()` function in your consumer file gets called with the key and should output instructions or configure your tool. See [new-platform.md](new-platform.md) for details.
129
+
130
+ ## For Agent Authors
131
+
132
+ If you're building an AI agent, make it a **consumer**:
133
+
134
+ ### Option 1: Document the command
135
+
136
+ Tell users to run:
137
+ ```bash
138
+ capit openrouter 5.00 --agent your-agent
139
+ ```
140
+
141
+ ### Option 2: Integrate directly
142
+
143
+ Add a handler in your setup script:
144
+
145
+ ```python
146
+ # In your agent's install/setup script
147
+ import subprocess
148
+
149
+ def setup_api_key():
150
+ result = subprocess.run(
151
+ ["capit", "openrouter", "5.00", "--agent", "your-agent"],
152
+ capture_output=True,
153
+ text=True
154
+ )
155
+ # Parse the key from output and configure
156
+ ```
157
+
158
+ ### Option 3: Create a custom consumer
159
+
160
+ Add your handler to capit (or fork and customize):
161
+
162
+ ```python
163
+ def send_to_youragent(key, platform, spend_cap):
164
+ click.echo(f"\n🔑 Limited key for {platform} (${spend_cap} cap)")
165
+ click.echo(f"Key: {key}")
166
+ click.echo(f"\nAdd to ~/.youragent/config:")
167
+ click.echo(f" api_key: {key}")
168
+ # Or write directly to config file
169
+ return key
170
+ ```
171
+
172
+ ## Administration
173
+
174
+ All admin commands use `--` prefix (Unix style):
175
+
176
+ ```bash
177
+ # List your stored master keys
178
+ capit --keys list
179
+
180
+ # Add a master key (stored locally for future use)
181
+ capit --keys add openrouter
182
+
183
+ # List actual API keys created on OpenRouter
184
+ capit --keys list -r openrouter
185
+ # Output:
186
+ # 4ab1e7e3ebc75228... prod-claude-abc123 $5 2026-03-19 [active]
187
+ # 5f54d6da2cdf0d47... dev-testing-def456 $1 2026-03-19 [active]
188
+
189
+ # Revoke a specific API key
190
+ capit --keys delete openrouter 4ab1e7e3ebc75228
191
+
192
+ # Remove a stored master key
193
+ capit --keys remove openrouter
194
+
195
+ # List platforms
196
+ capit --platforms
197
+
198
+ # List storage backends
199
+ capit --stores
200
+ ```
201
+
202
+ ## How It Works
203
+
204
+ 1. You run `capit openrouter 5.00`
205
+ 2. capit calls OpenRouter's Management API
206
+ 3. capit creates a **guardrail** with $5/month budget limit
207
+ 4. capit creates an **API key** with that guardrail attached
208
+ 5. You get back a limited key: `sk-or-v1-...`
209
+
210
+ The spending cap is **enforced by OpenRouter**, not just locally tracked. The key literally cannot spend more than the cap.
211
+
212
+ ## Platforms
213
+
214
+ capit works with multiple platforms:
215
+
216
+ ### OpenRouter (LLM APIs)
217
+
218
+ Creates keys with spending caps enforced by OpenRouter. Perfect for AI agents.
219
+
220
+ ```bash
221
+ capit openrouter 5.00 --agent claude
222
+ ```
223
+
224
+ ### Unkey (Rate-limited API keys)
225
+
226
+ Creates keys with rate limits and usage caps. Perfect for API access control.
227
+
228
+ ```bash
229
+ # 100 credits/month + 10 requests/minute rate limit
230
+ capit unkey 100 --name my-api --prefix prod
231
+ ```
232
+
233
+ Unkey supports:
234
+ - **Usage limits** - Cap total API calls (credits)
235
+ - **Rate limits** - Requests per second/minute/hour
236
+ - **Auto-refill** - Daily or monthly credit restoration
237
+ - **Key expiration** - Temporary keys that auto-expire
238
+
239
+ See [new-platform.md](new-platform.md) for adding more platforms.
240
+
241
+ ## Storage
242
+
243
+ Master keys are stored locally in `$HOME/.local/capit/`:
244
+ - `secrets.txt` - Your master keys (dotenv format)
245
+ - `master-lookup` - Maps platforms to storage backends
246
+
247
+ You can implement custom storage backends (YubiKey-gated, encrypted, etc.). See `capit/stores/dotenv.py` for the interface.
248
+
249
+ ## One-shot / Ephemeral Mode
250
+
251
+ Don't want to store anything? Use `-i` to enter your key once:
252
+
253
+ ```bash
254
+ capit openrouter 5.00 -i
255
+ ```
256
+
257
+ The key is used to create the limited key, then discarded. Next time you'll be prompted again. Perfect for:
258
+ - Trying capit for the first time
259
+ - CI/CD environments
260
+ - Shared machines
261
+
262
+ ## Why This Matters
263
+
264
+ AI agents are powerful but unpredictable. You should be able to:
265
+
266
+ 1. **Try new agents** without financial risk
267
+ 2. **Give different agents different budgets** (Claude gets $10, experimental agent gets $1)
268
+ 3. **Revoke access instantly** when you're done
269
+ 4. **Sleep soundly** knowing your credit card is safe
270
+
271
+ capit makes this trivial. One command. Done.
272
+
273
+ ## License
274
+
275
+ MIT