# AI/LiteLLM Debugging Guide

## Debugging AI Integration Issues

### Problem: "Invalid model name" error

```json
{"error":{"message":"/chat/completions: Invalid model name passed in model=gpt-4o-mini. 
Call `/v1/models` to view available models for your key.","type":"None","param":"None","code":"400"}}
```

**Debugging Steps:**

1. **Check available models:**
```bash
curl -s "https://YOUR_LITELLM_URL/v1/models" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

2. **Use correct model name from response** - model names like `minimax-2.7`, not `tiger-minimax` etc.

### Problem: "login fail" error

```json
{"base_resp":{"status_code":1004,"status_msg":"login fail: Please carry the API secret key 
in the 'Authorization' field of the request header"}}
```

**Causes:**
- Wrong API key format
- Invalid API key
- Key not configured in LiteLLM

**Debugging Steps:**

1. Test API key directly:
```bash
curl -s -X POST "https://api.minimax.chat/v1/text/chatcompletion_v2" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_KEY" \
  -d '{"model":"abab7.5-chat","messages":[{"role":"user","content":"hi"}]}'
```

### Problem: Empty response

**Error:**
```json
{"reply":"Sorry, I couldn't get a response."}
```

**Debugging Steps:**

1. Add debug logging:
```typescript
const data = await response.json();
console.log("API response:", data);
return NextResponse.json({ reply: data.choices?.[0]?.message?.content });
```

2. Check server health:
```bash
curl -s "https://YOUR_LITELLM_URL/health"
```

### Problem: Network errors (fetch failed)

**Debug:**
1. Check URL accessibility from deployed server
2. Use full domain, not internal hostname: `https://llm.manohargupta.com` not `http://litellm-gateway:4000`
3. Add `https://` prefix

## LiteLLM URL Pattern

```
https://llm.manohargupta.com/v1/chat/completions
```

Expected models from LiteLLM:
- `minimax-2.7`
- `minimax-2.7-fast`
- `claude-haiku`
- `claude-sonnet`
- `nvidia-llama`

## API Key Format

For LiteLLM:
- Key: `sk-tiger-gateway-...` (your key)
- Header: `Authorization: Bearer sk-tiger-gateway-...`

For MiniMax direct:
- Different key format - check platform.minimax.ai

## Test Script

```bash
# Test LiteLLM
curl -s -X POST "https://llm.manohargupta.com/v1/chat/completions" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-tiger-gateway-YOUR_KEY" \
  -d '{"model":"minimax-2.7","messages":[{"role":"user","content":"hi"}]}'
```