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 {
#[arg(long, global = true)]
pub config: Option<PathBuf>,
#[arg(long, global = true)]
pub profile: Option<String>,
#[arg(long, global = true)]
pub api_key: Option<String>,
#[arg(long, global = true)]
pub management_key: Option<String>,
#[arg(long, global = true)]
pub base_url: Option<String>,
#[arg(long, global = true, value_enum, default_value_t = OutputFormat::Table)]
pub output: OutputFormat,
}
#[derive(Debug, Clone, Subcommand)]
pub enum ProfileCommands {
Show,
}
#[derive(Debug, Clone, Subcommand)]
pub enum ConfigCommands {
Show,
Path,
}
#[derive(Debug, Clone, Args)]
pub struct CreditsChargeArgs {
#[arg(long)]
pub amount: f64,
#[arg(long)]
pub sender: String,
#[arg(long)]
pub chain_id: u32,
}
#[derive(Debug, Clone, Subcommand)]
pub enum CreditsCommands {
Show,
Charge(CreditsChargeArgs),
}
#[derive(Debug, Clone, Args)]
pub struct UsageActivityArgs {
#[arg(long)]
pub date: Option<String>,
}
#[derive(Debug, Clone, Subcommand)]
pub enum UsageCommands {
Activity(UsageActivityArgs),
}
#[derive(Debug, Clone, Subcommand)]
pub enum OrganizationMemberCommands {
List(PaginationArgs),
}
#[derive(Debug, Clone, Subcommand)]
pub enum OrganizationCommands {
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 {
#[arg(long, value_enum, conflicts_with = "supported_parameter")]
pub category: Option<ModelCategoryArg>,
#[arg(long, value_enum, conflicts_with = "category")]
pub supported_parameter: Option<SupportedParameterArg>,
}
#[derive(Debug, Clone, Args)]
pub struct ModelsShowArgs {
pub model_id: String,
}
#[derive(Debug, Clone, Args)]
pub struct ModelsEndpointsArgs {
pub model_id: String,
}
#[derive(Debug, Clone, Subcommand)]
pub enum ModelsCommands {
List(ModelsListArgs),
Show(ModelsShowArgs),
Endpoints(ModelsEndpointsArgs),
}
#[derive(Debug, Clone, Subcommand)]
pub enum ProvidersCommands {
List,
}
#[derive(Debug, Clone, Args)]
pub struct KeysListArgs {
#[arg(long)]
pub offset: Option<u32>,
#[arg(long)]
pub include_disabled: bool,
}
#[derive(Debug, Clone, Args)]
pub struct KeysCreateArgs {
#[arg(long)]
pub name: String,
#[arg(long)]
pub limit: Option<f64>,
}
#[derive(Debug, Clone, Args)]
pub struct KeysGetArgs {
pub hash: String,
}
#[derive(Debug, Clone, Args)]
pub struct KeysUpdateArgs {
pub hash: String,
#[arg(long)]
pub name: Option<String>,
#[arg(long)]
pub limit: Option<f64>,
#[arg(long, conflicts_with = "enable")]
pub disable: bool,
#[arg(long, conflicts_with = "disable")]
pub enable: bool,
}
#[derive(Debug, Clone, Args)]
pub struct KeysDeleteArgs {
pub hash: String,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, Clone, Subcommand)]
pub enum KeysCommands {
List(KeysListArgs),
Create(KeysCreateArgs),
Get(KeysGetArgs),
Update(KeysUpdateArgs),
Delete(KeysDeleteArgs),
}
#[derive(Debug, Clone, Args)]
pub struct PaginationArgs {
#[arg(long)]
pub offset: Option<u32>,
#[arg(long)]
pub limit: Option<u32>,
}
#[derive(Debug, Clone, Args)]
pub struct GuardrailsGetArgs {
pub id: String,
}
#[derive(Debug, Clone, Args)]
pub struct GuardrailsDeleteArgs {
pub id: String,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, Clone, Args)]
pub struct GuardrailsCreateArgs {
#[arg(long)]
pub name: String,
#[arg(long)]
pub description: Option<String>,
#[arg(long)]
pub limit_usd: Option<f64>,
#[arg(long)]
pub reset_interval: Option<String>,
#[arg(long = "allowed-provider")]
pub allowed_providers: Vec<String>,
#[arg(long = "allowed-model")]
pub allowed_models: Vec<String>,
#[arg(long)]
pub enforce_zdr: bool,
}
#[derive(Debug, Clone, Args)]
pub struct GuardrailsUpdateArgs {
pub id: String,
#[arg(long)]
pub name: Option<String>,
#[arg(long)]
pub description: Option<String>,
#[arg(long)]
pub limit_usd: Option<f64>,
#[arg(long)]
pub reset_interval: Option<String>,
#[arg(long = "allowed-provider", conflicts_with = "clear_allowed_providers")]
pub allowed_providers: Vec<String>,
#[arg(long = "allowed-model", conflicts_with = "clear_allowed_models")]
pub allowed_models: Vec<String>,
#[arg(long)]
pub clear_allowed_providers: bool,
#[arg(long)]
pub clear_allowed_models: bool,
#[arg(long, conflicts_with = "no_enforce_zdr")]
pub enforce_zdr: bool,
#[arg(long = "no-enforce-zdr", conflicts_with = "enforce_zdr")]
pub no_enforce_zdr: bool,
}
#[derive(Debug, Clone, Args)]
pub struct AssignmentListArgs {
#[arg(long)]
pub guardrail_id: Option<String>,
#[command(flatten)]
pub pagination: PaginationArgs,
}
#[derive(Debug, Clone, Args)]
pub struct KeyAssignmentApplyArgs {
pub guardrail_id: String,
#[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,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailKeyAssignmentCommands {
List(AssignmentListArgs),
Assign(KeyAssignmentApplyArgs),
Unassign(KeyAssignmentUnassignArgs),
}
#[derive(Debug, Clone, Args)]
pub struct MemberAssignmentApplyArgs {
pub guardrail_id: String,
#[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,
#[arg(long)]
pub yes: bool,
}
#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailMemberAssignmentCommands {
List(AssignmentListArgs),
Assign(MemberAssignmentApplyArgs),
Unassign(MemberAssignmentUnassignArgs),
}
#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailAssignmentCommands {
Keys {
#[command(subcommand)]
command: GuardrailKeyAssignmentCommands,
},
Members {
#[command(subcommand)]
command: GuardrailMemberAssignmentCommands,
},
}
#[derive(Debug, Clone, Subcommand)]
pub enum GuardrailsCommands {
List(PaginationArgs),
Create(GuardrailsCreateArgs),
Get(GuardrailsGetArgs),
Update(GuardrailsUpdateArgs),
Delete(GuardrailsDeleteArgs),
Assignments {
#[command(subcommand)]
command: GuardrailAssignmentCommands,
},
}
#[derive(Debug, Clone, Subcommand)]
pub enum Commands {
Profile {
#[command(subcommand)]
command: ProfileCommands,
},
Config {
#[command(subcommand)]
command: ConfigCommands,
},
Credits {
#[command(subcommand)]
command: CreditsCommands,
},
Models {
#[command(subcommand)]
command: ModelsCommands,
},
Providers {
#[command(subcommand)]
command: ProvidersCommands,
},
Keys {
#[command(subcommand)]
command: KeysCommands,
},
Guardrails {
#[command(subcommand)]
command: GuardrailsCommands,
},
Organization {
#[command(subcommand)]
command: OrganizationCommands,
},
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,
}