x-ai 0.1.0

✨ A cli, tui, and sdk for interacting with the 𝕏-AI API
Documentation
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! CLI argument definitions for the x-ai command-line tool.

#[cfg(feature = "cli")]
use clap::builder::styling::{AnsiColor, Effects, Styles};
#[cfg(feature = "cli")]
use clap::{Args, Parser, Subcommand};

#[cfg(feature = "cli")]
fn styles() -> Styles {
    Styles::styled()
        .header(AnsiColor::Cyan.on_default() | Effects::BOLD)
        .usage(AnsiColor::Cyan.on_default() | Effects::BOLD)
        .literal(AnsiColor::Blue.on_default() | Effects::BOLD)
        .error(AnsiColor::Red.on_default() | Effects::BOLD)
        .placeholder(AnsiColor::Green.on_default())
}

#[cfg(feature = "cli")]
#[derive(Parser, Debug, Clone)]
#[command(
    author  = "Mahmoud Harmouch",
    version,
    name    = "xai",
    propagate_version = true,
    styles  = styles(),
    help_template = r#"{about}
{usage-heading} {usage}

{all-args}{after-help}

AUTHORS:
    {author}
"#,
    about = r#"
 █████ █████   █████████   █████
▒▒███ ▒▒███   ███▒▒▒▒▒███ ▒▒███ 
 ▒▒███ ███   ▒███    ▒███  ▒███ 
  ▒▒█████    ▒███████████  ▒███ 
   ███▒███   ▒███▒▒▒▒▒███  ▒███ 
  ███ ▒▒███  ▒███    ▒███  ▒███ 
 █████ █████ █████   █████ █████
▒▒▒▒▒ ▒▒▒▒▒ ▒▒▒▒▒   ▒▒▒▒▒ ▒▒▒▒▒ 

A command-line tool for interacting with the xAI Grok API.

FUNCTIONALITIES:
  - Chat Completions   : Chat with Grok models.
  - Text Completions   : Legacy text completions.
  - Embeddings         : Create text embeddings.
  - List Models        : List all available models.
  - Get Model          : Get info about a specific model.
  - API Key Info       : Inspect the current API key.

USAGE:
  xai [OPTIONS] <COMMAND>

EXAMPLES:
  Run TUI (default):
    xai

  Chat:
    xai chat -t "What is the answer to life?"

  Stream chat:
    xai chat -t "Tell me a story" --stream

  Text completion (legacy):
    xai complete -p "Once upon a time"

  Create embeddings:
    xai embed -t "Hello world"

  List models:
    xai models

  Get model info:
    xai model -m grok-4

  API key info:
    xai apikey

For more information, visit: github.com/wiseaidotdev/x-ai
"#
)]
pub struct Cli {
    /// xAI API key (overrides XAI_API_KEY env var).
    #[arg(short = 'k', long)]
    pub api_key: Option<String>,
    /// Model to use (default: grok-4).
    #[arg(short, long)]
    pub model: Option<String>,
    #[command(subcommand)]
    pub cmd: Option<Command>,
}

#[cfg(feature = "cli")]
#[derive(Subcommand, Debug, Clone)]
pub enum Command {
    /// Chat with a Grok model.
    Chat(Chat),
    /// Legacy text completion.
    Complete(Complete),
    /// Create text embeddings.
    Embed(Embed),
    /// List all available models.
    Models(Models),
    /// Get details for a specific model.
    Model(ModelInfo),
    /// Show API key information.
    Apikey(Apikey),
}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Chat {
    /// The message to send.
    #[arg(short, long)]
    pub text: String,
    /// Enable streaming output (typed character-by-character).
    #[arg(short, long, default_value_t = false)]
    pub stream: bool,
}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Complete {
    /// The prompt text.
    #[arg(short, long)]
    pub prompt: String,
    /// Maximum tokens to generate.
    #[arg(long, default_value_t = 256)]
    pub max_tokens: u32,
}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Embed {
    /// Text to embed.
    #[arg(short, long)]
    pub text: String,
    /// Encoding format (default: float).
    #[arg(short, long, default_value = "float")]
    pub encoding_format: String,
}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Models {}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct ModelInfo {
    /// Model ID to look up.
    #[arg(short, long)]
    pub model_id: String,
}

#[cfg(feature = "cli")]
#[derive(Args, Debug, Clone)]
pub struct Apikey {}
// Copyright 2026 Mahmoud Harmouch.
//
// Licensed under the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.