This example demonstrates how to use custom shortcuts in the Inference Gateway CLI.
Shortcuts are user-defined commands that execute shell commands, scripts, or AI-powered operations within the chat interface. They support:
- Simple commands: Execute any shell command or script
- AI-powered snippets: Execute commands, send output to LLM, use response in templates
- Parameter support: Pass arguments to shortcuts
- JSON output parsing: Structure command output for AI processing
Container Environment: The CLI runs in Alpine Linux with
bashandjqpre-installed for scripting and JSON processing.
-
Copy environment file:
cp .env.example .env
-
Add your API key to
.env:ANTHROPIC_API_KEY=your-key-here # or OPENAI_API_KEY=your-key-here -
Start the services:
docker compose up -d
-
Run the CLI:
docker compose run --rm cli
-
Try the shortcuts:
/hello /sysinfo /review-comments
This example includes three types of shortcuts in .infer/shortcuts/custom-demo.yaml:
- name: hello
description: "Say hello from the container"
command: echo
args:
- "Hello from the Inference Gateway CLI! 🚀"Usage: /hello
- name: sysinfo
description: "Display system information"
command: bash
args:
- -c
- |
echo "=== System Information ==="
echo "Hostname: $(hostname)"
# ... more commandsUsage: /sysinfo
- name: review-comments
description: "Generate suggested replies to code review comments"
command: bash
args:
- -c
- |
# Fetch mock GitHub review comments
jq -n '{repo: "...", prNumber: "123", comments: [...]}'
snippet:
prompt: |
Draft professional replies to review comments...
Generate a gh CLI command to post all replies.
template: |
! {llm}Usage: /review-comments
How it works:
- Fetches mock review comments from a PR (simulates GitHub API)
- AI analyzes the comments and drafts professional replies
- AI generates an executable
ghCLI command with the replies - Command is placed in your input box with
!prefix - Review and press Enter to execute and post the replies to GitHub
This demonstrates the snippet + template feature where:
- The command outputs JSON data
- The snippet sends data to AI with instructions
- The template formats the AI response as an executable command
- Perfect for workflows that need human review before execution!
shortcuts:
- name: shortcut-name
description: "What this shortcut does"
command: bash
args:
- -c
- "echo 'Hello World'"shortcuts:
- name: ai-shortcut
description: "AI-powered operation"
command: bash
args:
- -c
- |
# Execute command and output JSON
jq -n --arg data "value" '{result: $data}'
snippet:
prompt: |
Analyze this data: {result}
Provide insights based on the data.
template: |
## Analysis Results
{llm}How it works:
commandexecutes and produces output (preferably JSON)- Output fields become variables (e.g.,
{result}) promptis sent to the LLM with variable substitution- LLM response becomes
{llm}variable templateformats the final output shown to user
The CLI includes several built-in shortcuts (available by default):
/help- Show help information/clear- Clear conversation history/exit- Exit the CLI/switch <conversation-id>- Switch conversations/theme <theme-name>- Change UI theme
-
Create a new file in
.infer/shortcuts/:touch .infer/shortcuts/custom-myshortcuts.yaml
-
Define your shortcuts:
shortcuts: - name: my-command description: "My custom command" command: echo args: - "My output"
-
Restart the CLI or reload configuration
-
Use your shortcut:
/my-command
- File naming: Use
custom-*.yamlfor custom shortcuts - Shell support: Both
bashandshare available in the container - JSON output: Use
jqto format command output for AI processing (pre-installed) - Error handling: Check command success and provide helpful error messages
- Parameter support: Use
$1,$2, etc. in bash scripts to accept arguments - Testing: Test shortcuts locally before adding to production configs
The docker-compose.yml mounts shortcuts as read-only:
volumes:
- ./.infer/shortcuts:/home/infer/.infer/shortcuts:roThis ensures:
- Shortcuts are available in the CLI
- Container cannot modify your local shortcuts
- Easy to version control your shortcuts
- Check out other examples in
examples/directory - Explore built-in shortcuts in the main
.infer/shortcuts/directory - Create shortcuts for your common workflows
Shortcut not found:
- Check file is in
.infer/shortcuts/directory - Verify YAML syntax is correct
- Restart the CLI container
AI snippet not working:
- Ensure API key is configured
- Check prompt formatting and variable names
- Verify JSON output structure
docker compose down -vThis removes containers and volumes, including persisted conversation data.