CLI Tool
The Cortex Command Line Interface (CLI) provides a convenient way to interact with the Cortex API directly from your terminal.
๐ฆ Installationโ
npm (Node.js)โ
npm install -g @cortex/cli
Homebrew (macOS)โ
brew install cortex-ai/tap/cortex
Direct Downloadโ
# Linux/macOS
curl -fsSL https://get.usecortex.co | sh
# Windows (PowerShell)
iwr -useb https://get.usecortex.co/windows | iex
Dockerโ
docker run --rm -it cortexai/cli:latest --help
๐ Quick Startโ
Authenticationโ
# Set API key (interactive)
cortex auth login
# Set API key directly
cortex auth set-key cortex_sk_your_api_key_here
# Use environment variable
export CORTEX_API_KEY=cortex_sk_your_api_key_here
Basic Usageโ
# Search the web
cortex search "latest AI developments"
# Extract content from URL
cortex extract https://example.com/article
# Validate a claim
cortex validate "The iPhone 15 supports USB-C"
# Check account status
cortex status
๐ Search Commandsโ
Basic Searchโ
# Simple search
cortex search "quantum computing breakthrough"
# Search with options
cortex search "Tesla stock analysis" \
--max-results 10 \
--language en \
--country us \
--recency week
Advanced Searchโ
# Search with domain filtering
cortex search "renewable energy news" \
--include-domains "reuters.com,bloomberg.com,bbc.com" \
--exclude-domains "reddit.com,twitter.com"
# Search with output format
cortex search "machine learning papers" \
--format markdown \
--output results.md
# Search with JSON output
cortex search "AI developments" \
--format json \
--output results.json \
--pretty
Search Optionsโ
| Option | Short | Description | Default |
|---|---|---|---|
--max-results | -n | Number of sources to analyze | 5 |
--language | -l | Target language code | auto |
--country | -c | Geographic focus | global |
--recency | -r | Time filter (day/week/month/year) | auto |
--format | -f | Output format (json/markdown/text) | text |
--output | -o | Output file path | stdout |
--include-domains | Comma-separated domains to include | ||
--exclude-domains | Comma-separated domains to exclude | ||
--cache | Enable result caching | true | |
--timeout | -t | Request timeout in seconds | 30 |
--pretty | -p | Pretty print JSON output | false |
--quiet | -q | Suppress progress output | false |
--verbose | -v | Verbose output | false |
Batch Searchโ
# Search multiple queries from file
cortex search --batch queries.txt --output-dir results/
# queries.txt
AI developments
quantum computing
renewable energy
blockchain technology
Interactive Searchโ
# Enter interactive mode
cortex search --interactive
# Interactive prompt
> Enter search query: latest tech news
> Max results [5]: 10
> Language [auto]: en
> Country [global]: us
> Searching...
๐ Extract Commandsโ
Basic Extractionโ
# Extract content from URL
cortex extract https://example.com/article
# Extract with specific format
cortex extract https://techcrunch.com/ai-news \
--format markdown \
--output article.md
Advanced Extractionโ
# Extract with metadata and images
cortex extract https://example.com/article \
--include-metadata \
--extract-images \
--extract-links \
--output-dir extracted/
# Batch extraction
cortex extract --batch urls.txt --output-dir content/
Extract Optionsโ
| Option | Short | Description | Default |
|---|---|---|---|
--format | -f | Output format (text/markdown/html/json) | text |
--output | -o | Output file path | stdout |
--output-dir | Output directory for batch processing | ||
--include-metadata | -m | Include page metadata | false |
--extract-images | Extract image URLs and metadata | false | |
--extract-links | Extract internal/external links | false | |
--clean-html | Remove ads and clutter | true | |
--timeout | -t | Request timeout in seconds | 30 |
--batch | -b | Process URLs from file |
โ Validate Commandsโ
Basic Validationโ
# Validate a claim
cortex validate "The Earth is round"
# Validate with sources
cortex validate "Tesla delivered 1.8M vehicles in 2023" \
--sources "tesla.com,reuters.com,bloomberg.com"
Advanced Validationโ
# Validate with context
cortex validate "Python is the most popular programming language" \
--domain technology \
--claim-type statistical \
--confidence-threshold 0.8
# Batch validation
cortex validate --batch claims.txt --output validation-results.json
Validate Optionsโ
| Option | Short | Description | Default |
|---|---|---|---|
--sources | -s | Comma-separated sources to check | |
--domain | -d | Subject domain (tech/science/finance/etc) | |
--claim-type | Type of claim (factual/statistical/opinion) | factual | |
--confidence-threshold | Minimum confidence required (0.0-1.0) | 0.7 | |
--require-primary | Require primary sources only | false | |
--max-sources | Maximum sources to analyze | 5 | |
--output | -o | Output file path | stdout |
--format | -f | Output format (json/text/markdown) | text |
--batch | -b | Process claims from file |
๐ Cache Commandsโ
Query Cacheโ
# Check if query is cached
cortex cache query "AI developments"
# Query with filters
cortex cache query "tech news" \
--max-age 3600 \
--include-expired
Store in Cacheโ
# Cache search results
cortex search "quantum computing" --cache-ttl 7200
# Manually store in cache
cortex cache store \
--query "AI developments" \
--content @content.json \
--ttl 3600 \
--trust-level high
Cache Managementโ
# View cache statistics
cortex cache stats
# Clear cache by tags
cortex cache clear --tags "outdated,temporary"
# Clear old entries
cortex cache clear --older-than "7 days ago"
# Clear all cache
cortex cache clear --all
๐ Monitoring Commandsโ
Usage Statisticsโ
# View current usage
cortex usage
# Usage for specific period
cortex usage --period month --breakdown day
# Detailed usage report
cortex usage --period week --include-details --output usage-report.json
Health Statusโ
# Check system health
cortex health
# Health with details
cortex health --verbose
# Continuous health monitoring
cortex health --watch --interval 30
Audit Logsโ
# View recent audit logs
cortex audit --limit 100
# Filter audit logs
cortex audit \
--start-date "2025-01-01" \
--end-date "2025-01-09" \
--endpoint "/v1/search" \
--status success
๐ง Configurationโ
Config Fileโ
# Initialize config file
cortex config init
# Edit config
cortex config edit
# View current config
cortex config show
Config File Locationโ
- Linux/macOS:
~/.config/cortex/config.yaml - Windows:
%APPDATA%\cortex\config.yaml
Config File Exampleโ
# ~/.config/cortex/config.yaml
api_key: cortex_sk_your_api_key_here
base_url: https://api.usecortex.co/v1
timeout: 30
max_retries: 3
output_format: text
cache_enabled: true
# Default search options
defaults:
search:
max_results: 5
language: en
include_sources: true
extract:
format: markdown
include_metadata: true
validate:
confidence_threshold: 0.8
require_primary_sources: false
# Output settings
output:
pretty_json: true
colors: true
progress: true
Environment Variablesโ
# API Configuration
export CORTEX_API_KEY=cortex_sk_your_api_key_here
export CORTEX_BASE_URL=https://api.usecortex.co/v1
export CORTEX_TIMEOUT=30
# Output Configuration
export CORTEX_OUTPUT_FORMAT=json
export CORTEX_PRETTY_JSON=true
export CORTEX_NO_COLOR=false
export CORTEX_QUIET=false
Profile Managementโ
# Create profiles for different environments
cortex config profile create production
cortex config profile create staging
cortex config profile create development
# Switch between profiles
cortex config profile use production
# List profiles
cortex config profile list
# Set profile-specific settings
cortex config set api_key cortex_sk_prod_key --profile production
cortex config set base_url https://staging.api.usecortex.co/v1 --profile staging
๐งช Advanced Usageโ
Scripting and Automationโ
#!/bin/bash
# Daily news monitoring script
DATE=$(date +%Y%m%d)
TOPICS=("artificial intelligence" "quantum computing" "renewable energy")
for topic in "${TOPICS[@]}"; do
echo "Searching for: $topic"
cortex search "$topic latest news" \
--recency day \
--max-results 5 \
--format json \
--output "news_${topic// /_}_${DATE}.json"
# Validate key claims from the results
if [ -f "news_${topic// /_}_${DATE}.json" ]; then
summary=$(jq -r '.data.summary' "news_${topic// /_}_${DATE}.json")
first_sentence=$(echo "$summary" | head -n1)
cortex validate "$first_sentence" \
--domain technology \
--output "validation_${topic// /_}_${DATE}.json"
fi
done
echo "Daily news monitoring completed"
Data Pipeline Integrationโ
# Content analysis pipeline
process_urls() {
local urls_file="$1"
local output_dir="$2"
mkdir -p "$output_dir"
while IFS= read -r url; do
if [[ $url =~ ^https?:// ]]; then
filename=$(echo "$url" | sed 's|[^a-zA-Z0-9]|_|g')
# Extract content
cortex extract "$url" \
--format markdown \
--include-metadata \
--output "$output_dir/${filename}.md"
# Get content summary via search
domain=$(echo "$url" | sed 's|https\?://||' | cut -d'/' -f1)
cortex search "site:$domain content analysis" \
--max-results 3 \
--format json \
--output "$output_dir/${filename}_context.json"
fi
done < "$urls_file"
}
# Usage
process_urls "urls.txt" "processed_content/"
Monitoring and Alertingโ
# Health monitoring with alerts
monitor_health() {
while true; do
health_status=$(cortex health --format json | jq -r '.data.status')
if [ "$health_status" != "healthy" ]; then
echo "ALERT: Cortex health status is $health_status"
# Send notification (replace with your notification method)
curl -X POST https://hooks.slack.com/your-webhook \
-d "{\"text\": \"Cortex health alert: $health_status\"}"
fi
sleep 300 # Check every 5 minutes
done
}
# Usage monitoring with limits
check_usage() {
usage=$(cortex usage --format json)
usage_percent=$(echo "$usage" | jq -r '.data.current_period.usage_percentage')
if (( $(echo "$usage_percent > 80" | bc -l) )); then
echo "WARNING: Usage at ${usage_percent}%"
# Take action based on usage
if (( $(echo "$usage_percent > 90" | bc -l) )); then
echo "CRITICAL: Usage at ${usage_percent}% - throttling requests"
export CORTEX_RATE_LIMIT=true
fi
fi
}
๐ Batch Processingโ
Bulk Operationsโ
# Process large datasets
cortex search --batch large_queries.txt \
--max-results 10 \
--output-dir search_results/ \
--format json \
--parallel 5 \
--rate-limit 50
# Extract from URL list
cortex extract --batch url_list.txt \
--output-dir extracted_content/ \
--format markdown \
--include-metadata \
--parallel 3
Progress Trackingโ
# Show progress for long operations
cortex search --batch queries.txt \
--output-dir results/ \
--progress \
--log-file batch.log
# Resume interrupted batch job
cortex search --batch queries.txt \
--output-dir results/ \
--resume \
--skip-existing
๐ Output Formatsโ
JSON Outputโ
# Pretty JSON
cortex search "AI news" --format json --pretty
# Compact JSON for scripting
cortex search "AI news" --format json --compact
# Extract specific fields
cortex search "AI news" --format json | jq '.data.summary'
Markdown Outputโ
# Generate markdown report
cortex search "quarterly tech review" \
--format markdown \
--output tech_review.md \
--max-results 15
# Combine multiple searches into report
{
echo "# Tech News Summary"
echo "Generated on $(date)"
echo
cortex search "AI developments" --format markdown
echo
cortex search "quantum computing news" --format markdown
echo
cortex search "renewable energy updates" --format markdown
} > tech_summary.md
Custom Templatesโ
# Use custom output template
cortex search "company news" \
--template custom_template.jinja2 \
--output formatted_results.html
# Template variables available:
# - query, summary, sources, metadata, timestamp
๐ Debugging and Troubleshootingโ
Verbose Modeโ
# Enable verbose logging
cortex search "test query" --verbose
# Debug HTTP requests
cortex search "test query" --debug-http
# Trace execution
cortex search "test query" --trace
Error Handlingโ
# Continue on errors
cortex extract --batch urls.txt \
--output-dir content/ \
--continue-on-error \
--error-log errors.log
# Retry failed requests
cortex search "test query" \
--max-retries 5 \
--retry-delay 2
# Validate config before running
cortex config validate
Log Filesโ
# Set log level
cortex search "query" --log-level debug
# Custom log file
cortex search "query" --log-file /tmp/cortex.log
# View recent logs
cortex logs --tail 100
# Filter logs by level
cortex logs --level error --since "1 hour ago"
๐ Help and Documentationโ
Getting Helpโ
# General help
cortex --help
# Command-specific help
cortex search --help
cortex extract --help
cortex validate --help
# Show all available commands
cortex commands
# Show examples for command
cortex search --examples
Version Informationโ
# Show version
cortex --version
# Show detailed version info
cortex version --full
# Check for updates
cortex update --check
# Update CLI
cortex update --install
Completionโ
# Install shell completion
cortex completion install
# Bash completion
cortex completion bash > /etc/bash_completion.d/cortex
# Zsh completion
cortex completion zsh > ~/.zsh/completions/_cortex
# Fish completion
cortex completion fish > ~/.config/fish/completions/cortex.fish
๐ก Tips and Best Practicesโ
Performance Optimizationโ
# Use caching for repeated queries
cortex search "daily news" --cache-ttl 3600
# Parallel processing for batch operations
cortex extract --batch urls.txt --parallel 5
# Adjust timeout for slow sources
cortex extract "https://slow-site.com" --timeout 60
Cost Optimizationโ
# Check usage before expensive operations
cortex usage --current
# Use cache to avoid duplicate requests
cortex cache query "expensive query" || cortex search "expensive query"
# Set rate limits for automated scripts
export CORTEX_RATE_LIMIT=30 # requests per minute
Security Best Practicesโ
# Store API key securely
cortex auth set-key --from-stdin < api_key.txt
# Use environment variables in CI/CD
export CORTEX_API_KEY="${CORTEX_API_KEY_SECRET}"
# Rotate API keys regularly
cortex auth rotate-key --backup-old
Next: RAG Integration โ - Integrate with Retrieval-Augmented Generation systems