cllient 0.2.1

A comprehensive Rust client for LLM APIs with unified interface and model management
Documentation
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
# Installation & Setup

Complete guide for installing and configuring cllient.

## Prerequisites

### System Requirements

- **Rust** 1.70.0 or later
- **Git** for cloning the repository
- **jq** for JSON processing in Makefile utilities (optional)

### Operating Systems

- **Linux** (Ubuntu 20.04+, RHEL 8+, Arch Linux)
-**macOS** (10.15+, Apple Silicon and Intel)
-**Windows** (Windows 10+, WSL2 recommended)

## Installation Methods

### Option 1: Install from Source (Recommended)

```bash
# Clone the repository
git clone https://github.com/yourusername/cllient.git
cd cllient

# Install with Cargo
cargo install --path .

# Verify installation
cllient --help
```

### Option 2: Development Installation

```bash
# Clone and build for development
git clone https://github.com/yourusername/cllient.git
cd cllient

# Build in development mode
cargo build

# Run directly (without installing)
cargo run --bin cllient -- list
```

### Option 3: Pre-built Binaries (Future)

```bash
# Download from GitHub releases (when available)
curl -L https://github.com/yourusername/cllient/releases/latest/download/cllient-linux.tar.gz | tar xz
sudo mv cllient /usr/local/bin/
```

## Environment Setup

### 1. Copy Environment Template

```bash
# Copy the example environment file
cp .env.example .env
```

### 2. Add API Keys

Edit `.env` with your API keys:

```bash
# Core providers (required for basic functionality)
OPENAI_API_KEY=sk-proj-your-openai-key-here
ANTHROPIC_API_KEY=sk-ant-api03-your-anthropic-key-here
DEEPSEEK_API_KEY=sk-your-deepseek-key-here

# Additional providers (optional)
GOOGLE_AI_API_KEY=your-google-ai-key-here
COHERE_API_KEY=your-cohere-key-here
AZURE_OPENAI_API_KEY=your-azure-key-here
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
```

### 3. Get API Keys

#### OpenAI
1. Visit [OpenAI Platform]https://platform.openai.com/api-keys
2. Sign in or create account
3. Click "Create new secret key"
4. Copy the key to your `.env` file

#### Anthropic
1. Visit [Anthropic Console]https://console.anthropic.com/
2. Sign in or create account
3. Navigate to "API Keys"
4. Create a new key
5. Copy the key to your `.env` file

#### DeepSeek
1. Visit [DeepSeek Platform]https://platform.deepseek.com/api_keys
2. Sign in or create account
3. Generate API key
4. Copy the key to your `.env` file

#### Google AI
1. Visit [Google AI Studio]https://makersuite.google.com/app/apikey
2. Sign in with Google account
3. Create API key
4. Copy the key to your `.env` file

### 4. Test Configuration

```bash
# Test API connectivity
cllient ask gpt-4o-mini "Hello, world!" && echo "✅ OpenAI working"
cllient ask claude-3-haiku-20240307 "Hello!" && echo "✅ Anthropic working"
cllient ask deepseek-chat "Hello!" && echo "✅ DeepSeek working"

# List available models
cllient list | head -10
```

## Configuration Options

### Custom Configuration Directory

```bash
# Create custom config directory
mkdir -p ~/.config/cllient/{service,family}

# Set environment variable
export CLLIENT_CONFIG_DIR="$HOME/.config/cllient"

# Or add to shell profile
echo 'export CLLIENT_CONFIG_DIR="$HOME/.config/cllient"' >> ~/.bashrc
```

### Shell Integration

Add convenient aliases to your shell profile:

```bash
# Add to ~/.bashrc, ~/.zshrc, or ~/.profile

# Quick AI assistant
alias ai='cllient ask gpt-4o-mini'
alias ask='cllient ask'
alias stream='cllient stream'
alias chat='cllient chat'

# Model shortcuts
alias gpt='cllient ask gpt-4o-mini'
alias claude='cllient ask claude-3-haiku-20240307'
alias deepseek='cllient ask deepseek-chat'

# Development helpers
alias ai-code='cllient ask deepseek-coder'
alias ai-creative='cllient ask claude-3-opus-20240229'
```

### Logging Configuration

```bash
# Enable debug logging
export RUST_LOG=debug

# Component-specific logging
export RUST_LOG=cllient::client=debug,cllient::streaming=trace

# Log to file
export RUST_LOG=info
cllient ask gpt-4o-mini "test" 2>&1 | tee cllient.log
```

## Verification

### Basic Functionality Test

```bash
# Test installation
cllient --version

# Test configuration
cllient list | head -5

# Test basic completion
cllient ask deepseek-chat "What is 2+2?"

# Test streaming
cllient stream gpt-4o-mini "Count to 5"

# Test JSON output
cllient --json list claude | head -1
```

### Performance Test

```bash
# Test response times
time cllient ask gpt-4o-mini "Quick test"
time cllient ask claude-3-haiku-20240307 "Quick test"
time cllient ask deepseek-chat "Quick test"

# Test streaming performance
time cllient stream deepseek-chat "Count from 1 to 10"
```

## Troubleshooting

### Common Issues

#### "cllient: command not found"

**Solution**: Ensure Cargo's bin directory is in your PATH:

```bash
# Add to ~/.bashrc or ~/.zshrc
export PATH="$HOME/.cargo/bin:$PATH"

# Reload shell
source ~/.bashrc
```

#### "API key not found" errors

**Solution**: Check environment configuration:

```bash
# Verify .env file exists
ls -la .env

# Check environment variables
echo $OPENAI_API_KEY
echo $ANTHROPIC_API_KEY

# Test API key format
if [[ $OPENAI_API_KEY == sk-* ]]; then echo "✅ OpenAI key format OK"; else echo "❌ Invalid OpenAI key format"; fi
```

#### "Model not found" errors

**Solution**: List available models and check spelling:

```bash
# List all models
cllient list

# Search for specific model
cllient list | grep -i "gpt-4o"
cllient list | grep -i "claude"

# Use exact model IDs
cllient ask gpt-4o-mini "test"  # ✅ Correct
cllient ask gpt4o-mini "test"   # ❌ Incorrect
```

#### Network/SSL issues

**Solution**: Check network connectivity and SSL:

```bash
# Test network connectivity
curl -I https://api.openai.com
curl -I https://api.anthropic.com

# Update CA certificates (Linux)
sudo apt-get update && sudo apt-get install ca-certificates

# Update CA certificates (macOS)
brew install ca-certificates
```

#### Permission errors

**Solution**: Fix file permissions:

```bash
# Fix .env permissions
chmod 600 .env

# Fix configuration directory permissions
chmod -R 755 ~/.config/cllient
```

### Advanced Debugging

#### Enable verbose logging

```bash
# Maximum verbosity
RUST_LOG=trace cllient --verbose ask gpt-4o-mini "debug test"

# Component-specific debugging
RUST_LOG=cllient::config=debug cllient list
RUST_LOG=cllient::client=debug cllient ask gpt-4o-mini "test"
RUST_LOG=cllient::streaming=trace cllient stream deepseek-chat "test"
```

#### Validate configuration

```bash
# Check embedded configurations
cllient list-services

# Validate specific model
cllient --json list | jq '.[] | select(.id == "gpt-4o-mini")'

# Test configuration loading
CLLIENT_CONFIG_DIR=/nonexistent cllient list  # Should still work with embedded configs
```

#### Network diagnostics

```bash
# Test API endpoints
curl -H "Authorization: Bearer $OPENAI_API_KEY" https://api.openai.com/v1/models
curl -H "x-api-key: $ANTHROPIC_API_KEY" https://api.anthropic.com/v1/messages

# Check proxy settings
echo $http_proxy
echo $https_proxy

# Bypass proxy temporarily
unset http_proxy https_proxy
cllient ask gpt-4o-mini "proxy test"
```

## System Integration

### systemd Service (Linux)

```bash
# Create service file
sudo tee /etc/systemd/system/cllient-server.service << EOF
[Unit]
Description=cllient LLM Client Server
After=network.target

[Service]
Type=simple
User=cllient
WorkingDirectory=/opt/cllient
Environment=RUST_LOG=info
EnvironmentFile=/opt/cllient/.env
ExecStart=/usr/local/bin/cllient server
Restart=always

[Install]
WantedBy=multi-user.target
EOF

# Enable and start
sudo systemctl enable cllient-server
sudo systemctl start cllient-server
```

### Docker Setup

```dockerfile
# Dockerfile
FROM rust:1.70 as builder

WORKDIR /app
COPY . .
RUN cargo build --release

FROM debian:bookworm-slim
RUN apt-get update && apt-get install -y ca-certificates
COPY --from=builder /app/target/release/cllient /usr/local/bin/
COPY .env.example /.env

ENTRYPOINT ["cllient"]
CMD ["--help"]
```

```bash
# Build and run
docker build -t cllient .
docker run -it --env-file .env cllient list
```

### GitHub Codespaces

```json
// .devcontainer/devcontainer.json
{
  "name": "cllient development",
  "image": "mcr.microsoft.com/devcontainers/rust:1.70",
  "features": {
    "ghcr.io/devcontainers/features/github-cli:1": {}
  },
  "postCreateCommand": "cargo build",
  "customizations": {
    "vscode": {
      "extensions": [
        "rust-lang.rust-analyzer"
      ]
    }
  }
}
```

## Performance Optimization

### Configuration Tuning

```bash
# Use faster models for development
export AI_MODEL=deepseek-chat  # Fastest, cheapest

# Enable connection reuse
export RUST_LOG=reqwest::connect=debug

# Optimize for batch processing
export CLLIENT_BATCH_SIZE=10
```

### Shell Completion

```bash
# Generate completions (future feature)
cllient completions bash > ~/.bash_completion.d/cllient
cllient completions zsh > ~/.oh-my-zsh/completions/_cllient
cllient completions fish > ~/.config/fish/completions/cllient.fish
```

---

**Next**: [2. CLI Usage Guide](2_cli-usage.md) | [4. Configuration](4_configuration.md)