openrouter-cli 0.1.3

CLI for OpenRouter account and SDK workflows
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
use std::path::PathBuf;

use clap::{Args, Parser, Subcommand, ValueEnum};

#[derive(Debug, Clone, Copy, Eq, PartialEq, ValueEnum)]
pub enum OutputFormat {
    #[value(name = "table", alias = "text")]
    Table,
    Json,
}

#[derive(Debug, Clone, Args)]
pub struct GlobalOptions {
    /// Path to CLI profile config TOML.
    #[arg(long, global = true)]
    pub config: Option<PathBuf>,

    /// Profile name to use.
    #[arg(long, global = true)]
    pub profile: Option<String>,

    /// Override API key (highest priority).
    #[arg(long, global = true)]
    pub api_key: Option<String>,

    /// Override management key (highest priority).
    #[arg(long, global = true)]
    pub management_key: Option<String>,

    /// Override OpenRouter API base URL.
    #[arg(long, global = true)]
    pub base_url: Option<String>,

    /// Output format.
    #[arg(long, global = true, value_enum, default_value_t = OutputFormat::Table)]
    pub output: OutputFormat,
}

#[derive(Debug, Clone, Subcommand)]
pub enum ProfileCommands {
    /// Show resolved profile and auth sources.
    Show,
}

#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommands {
    /// Show resolved configuration snapshot.
    Show,
    /// Print the resolved config file path.
    Path,
}

#[derive(Debug, Clone, Args)]
pub struct CreditsChargeArgs {
    /// Charge amount in USD.
    #[arg(long)]
    pub amount: f64,

    /// Sender wallet address.
    #[arg(long)]
    pub sender: String,

    /// Chain ID for the charge.
    #[arg(long)]
    pub chain_id: u32,
}

#[derive(Debug, Clone, Subcommand)]
pub enum CreditsCommands {
    /// Show credit totals for the authenticated account.
    Show,
    /// Create a Coinbase charge.
    Charge(CreditsChargeArgs),
}

#[derive(Debug, Clone, Args)]
pub struct UsageActivityArgs {
    /// Optional date in YYYY-MM-DD.
    #[arg(long)]
    pub date: Option<String>,
}

#[derive(Debug, Clone, Subcommand)]
pub enum UsageCommands {
    /// Show activity grouped by endpoint.
    Activity(UsageActivityArgs),
}

#[derive(Debug, Clone, Subcommand)]
pub enum OrganizationMemberCommands {
    /// List organization members.
    List(PaginationArgs),
}

#[derive(Debug, Clone, Subcommand)]
pub enum OrganizationCommands {
    /// Organization member commands.
    Members {
        #[command(subcommand)]
        command: OrganizationMemberCommands,
    },
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, ValueEnum)]
pub enum ModelCategoryArg {
    Roleplay,
    Programming,
    Marketing,
    #[value(name = "marketing/seo", alias = "marketing-seo")]
    MarketingSeo,
    Technology,
    Science,
    Translation,
    Legal,
    Finance,
    Health,
    Trivia,
    Academia,
}

#[derive(Debug, Clone, Copy, Eq, PartialEq, ValueEnum)]
pub enum SupportedParameterArg {
    #[value(name = "tools")]
    Tools,
    #[value(name = "temperature")]
    Temperature,
    #[value(name = "top_p")]
    TopP,
    #[value(name = "top_k")]
    TopK,
    #[value(name = "min_p")]
    MinP,
    #[value(name = "top_a")]
    TopA,
    #[value(name = "frequency_penalty")]
    FrequencyPenalty,
    #[value(name = "presence_penalty")]
    PresencePenalty,
    #[value(name = "repetition_penalty")]
    RepetitionPenalty,
    #[value(name = "max_tokens")]
    MaxTokens,
    #[value(name = "logit_bias")]
    LogitBias,
    #[value(name = "logprobs")]
    Logprobs,
    #[value(name = "top_logprobs")]
    TopLogprobs,
    #[value(name = "seed")]
    Seed,
    #[value(name = "response_format")]
    ResponseFormat,
    #[value(name = "structured_outputs")]
    StructuredOutputs,
    #[value(name = "stop")]
    Stop,
    #[value(name = "include_reasoning")]
    IncludeReasoning,
    #[value(name = "reasoning")]
    Reasoning,
    #[value(name = "web_search_options")]
    WebSearchOptions,
}

#[derive(Debug, Clone, Args)]
pub struct ModelsListArgs {
    /// Filter models by category.
    #[arg(long, value_enum, conflicts_with = "supported_parameter")]
    pub category: Option<ModelCategoryArg>,

    /// Filter models by supported parameter.
    #[arg(long, value_enum, conflicts_with = "category")]
    pub supported_parameter: Option<SupportedParameterArg>,
}

#[derive(Debug, Clone, Args)]
pub struct ModelsShowArgs {
    /// Model ID (for example: openai/gpt-4.1).
    pub model_id: String,
}

#[derive(Debug, Clone, Args)]
pub struct ModelsEndpointsArgs {
    /// Model ID (for example: openai/gpt-4.1).
    pub model_id: String,
}

#[derive(Debug, Clone, Subcommand)]
pub enum ModelsCommands {
    /// List models.
    List(ModelsListArgs),
    /// Show a single model by model ID.
    Show(ModelsShowArgs),
    /// List endpoints for a specific model.
    Endpoints(ModelsEndpointsArgs),
}

#[derive(Debug, Clone, Subcommand)]
pub enum ProvidersCommands {
    /// List providers.
    List,
}

#[derive(Debug, Clone, Args)]
pub struct KeysListArgs {
    /// Optional offset for key listing.
    #[arg(long)]
    pub offset: Option<u32>,

    /// Include disabled keys.
    #[arg(long)]
    pub include_disabled: bool,
}

#[derive(Debug, Clone, Args)]
pub struct KeysCreateArgs {
    /// Display name for the key.
    #[arg(long)]
    pub name: String,

    /// Optional spending limit in USD.
    #[arg(long)]
    pub limit: Option<f64>,
}

#[derive(Debug, Clone, Args)]
pub struct KeysGetArgs {
    /// Key hash.
    pub hash: String,
}

#[derive(Debug, Clone, Args)]
pub struct KeysUpdateArgs {
    /// Key hash.
    pub hash: String,

    /// Optional new display name.
    #[arg(long)]
    pub name: Option<String>,

    /// Optional new spending limit in USD.
    #[arg(long)]
    pub limit: Option<f64>,

    /// Disable this key.
    #[arg(long, conflicts_with = "enable")]
    pub disable: bool,

    /// Enable this key.
    #[arg(long, conflicts_with = "disable")]
    pub enable: bool,
}

#[derive(Debug, Clone, Args)]
pub struct KeysDeleteArgs {
    /// Key hash.
    pub hash: String,

    /// Confirm destructive action.
    #[arg(long)]
    pub yes: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub enum KeysCommands {
    /// List API keys.
    List(KeysListArgs),
    /// Create an API key.
    Create(KeysCreateArgs),
    /// Get a single API key.
    Get(KeysGetArgs),
    /// Update an API key.
    Update(KeysUpdateArgs),
    /// Delete an API key.
    Delete(KeysDeleteArgs),
}

#[derive(Debug, Clone, Args)]
pub struct PaginationArgs {
    /// Offset for pagination.
    #[arg(long)]
    pub offset: Option<u32>,

    /// Limit for pagination.
    #[arg(long)]
    pub limit: Option<u32>,
}

#[derive(Debug, Clone, Args)]
pub struct GuardrailsGetArgs {
    /// Guardrail ID.
    pub id: String,
}

#[derive(Debug, Clone, Args)]
pub struct GuardrailsDeleteArgs {
    /// Guardrail ID.
    pub id: String,

    /// Confirm destructive action.
    #[arg(long)]
    pub yes: bool,
}

#[derive(Debug, Clone, Args)]
pub struct GuardrailsCreateArgs {
    /// Guardrail name.
    #[arg(long)]
    pub name: String,

    /// Optional guardrail description.
    #[arg(long)]
    pub description: Option<String>,

    /// Optional spending cap in USD.
    #[arg(long)]
    pub limit_usd: Option<f64>,

    /// Optional reset interval (for example: daily, monthly).
    #[arg(long)]
    pub reset_interval: Option<String>,

    /// Allowed provider IDs.
    #[arg(long = "allowed-provider")]
    pub allowed_providers: Vec<String>,

    /// Allowed model IDs.
    #[arg(long = "allowed-model")]
    pub allowed_models: Vec<String>,

    /// Enforce ZDR.
    #[arg(long)]
    pub enforce_zdr: bool,
}

#[derive(Debug, Clone, Args)]
pub struct GuardrailsUpdateArgs {
    /// Guardrail ID.
    pub id: String,

    /// Optional new name.
    #[arg(long)]
    pub name: Option<String>,

    /// Optional new description.
    #[arg(long)]
    pub description: Option<String>,

    /// Optional new spending cap in USD.
    #[arg(long)]
    pub limit_usd: Option<f64>,

    /// Optional new reset interval.
    #[arg(long)]
    pub reset_interval: Option<String>,

    /// Replace allowed provider IDs.
    #[arg(long = "allowed-provider", conflicts_with = "clear_allowed_providers")]
    pub allowed_providers: Vec<String>,

    /// Replace allowed model IDs.
    #[arg(long = "allowed-model", conflicts_with = "clear_allowed_models")]
    pub allowed_models: Vec<String>,

    /// Clear all allowed providers (send empty list).
    #[arg(long)]
    pub clear_allowed_providers: bool,

    /// Clear all allowed models (send empty list).
    #[arg(long)]
    pub clear_allowed_models: bool,

    /// Set `enforce_zdr=true`.
    #[arg(long, conflicts_with = "no_enforce_zdr")]
    pub enforce_zdr: bool,

    /// Set `enforce_zdr=false`.
    #[arg(long = "no-enforce-zdr", conflicts_with = "enforce_zdr")]
    pub no_enforce_zdr: bool,
}

#[derive(Debug, Clone, Args)]
pub struct AssignmentListArgs {
    /// Optional guardrail ID. If omitted, lists global assignments.
    #[arg(long)]
    pub guardrail_id: Option<String>,

    #[command(flatten)]
    pub pagination: PaginationArgs,
}

#[derive(Debug, Clone, Args)]
pub struct KeyAssignmentApplyArgs {
    /// Guardrail ID.
    pub guardrail_id: String,

    /// One or more key hashes.
    #[arg(value_name = "KEY_HASH", required = true, num_args = 1..)]
    pub key_hashes: Vec<String>,
}

#[derive(Debug, Clone, Args)]
pub struct KeyAssignmentUnassignArgs {
    #[command(flatten)]
    pub request: KeyAssignmentApplyArgs,

    /// Confirm destructive action.
    #[arg(long)]
    pub yes: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailKeyAssignmentCommands {
    /// List key assignments.
    List(AssignmentListArgs),
    /// Assign keys to a guardrail.
    Assign(KeyAssignmentApplyArgs),
    /// Unassign keys from a guardrail.
    Unassign(KeyAssignmentUnassignArgs),
}

#[derive(Debug, Clone, Args)]
pub struct MemberAssignmentApplyArgs {
    /// Guardrail ID.
    pub guardrail_id: String,

    /// One or more member user IDs.
    #[arg(value_name = "MEMBER_USER_ID", required = true, num_args = 1..)]
    pub member_user_ids: Vec<String>,
}

#[derive(Debug, Clone, Args)]
pub struct MemberAssignmentUnassignArgs {
    #[command(flatten)]
    pub request: MemberAssignmentApplyArgs,

    /// Confirm destructive action.
    #[arg(long)]
    pub yes: bool,
}

#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailMemberAssignmentCommands {
    /// List member assignments.
    List(AssignmentListArgs),
    /// Assign members to a guardrail.
    Assign(MemberAssignmentApplyArgs),
    /// Unassign members from a guardrail.
    Unassign(MemberAssignmentUnassignArgs),
}

#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailAssignmentCommands {
    /// Key assignment operations.
    Keys {
        #[command(subcommand)]
        command: GuardrailKeyAssignmentCommands,
    },
    /// Member assignment operations.
    Members {
        #[command(subcommand)]
        command: GuardrailMemberAssignmentCommands,
    },
}

#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailsCommands {
    /// List guardrails.
    List(PaginationArgs),
    /// Create a guardrail.
    Create(GuardrailsCreateArgs),
    /// Get a guardrail.
    Get(GuardrailsGetArgs),
    /// Update a guardrail.
    Update(GuardrailsUpdateArgs),
    /// Delete a guardrail.
    Delete(GuardrailsDeleteArgs),
    /// Manage guardrail assignments.
    Assignments {
        #[command(subcommand)]
        command: GuardrailAssignmentCommands,
    },
}

#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
    /// Profile-related commands.
    Profile {
        #[command(subcommand)]
        command: ProfileCommands,
    },
    /// Configuration commands.
    Config {
        #[command(subcommand)]
        command: ConfigCommands,
    },
    /// Credits and billing commands.
    Credits {
        #[command(subcommand)]
        command: CreditsCommands,
    },
    /// Model discovery commands.
    Models {
        #[command(subcommand)]
        command: ModelsCommands,
    },
    /// Provider discovery commands.
    Providers {
        #[command(subcommand)]
        command: ProvidersCommands,
    },
    /// API key management commands.
    Keys {
        #[command(subcommand)]
        command: KeysCommands,
    },
    /// Guardrail management commands.
    Guardrails {
        #[command(subcommand)]
        command: GuardrailsCommands,
    },
    /// Organization management commands.
    Organization {
        #[command(subcommand)]
        command: OrganizationCommands,
    },
    /// Usage commands.
    Usage {
        #[command(subcommand)]
        command: UsageCommands,
    },
}

#[derive(Debug, Clone, Parser)]
#[command(name = "openrouter-cli", version, about = "OpenRouter CLI", long_about = None)]
pub struct Cli {
    #[command(flatten)]
    pub global: GlobalOptions,

    #[command(subcommand)]
    pub command: Commands,
}