Using Claude Code
This guide explains how to set up Claude Code, Anthropic’s command-line interface for Claude, to work with Liona. By using Liona with Claude Code, you can securely access Claude’s capabilities in your development environment while maintaining control over spending.
Understanding Claude Code Integration
Claude Code is a powerful developer tool that brings Claude AI directly into your command-line environment. When integrated with Liona:
- Your teams can access Claude AI models without needing individual API keys
- You maintain centralized spending controls and usage limits
- All usage is tracked and can be monitored in your Liona dashboard
Setting Up Claude Code with Liona
Install Claude Code
First, if you haven’t already, install Claude Code using npm:
npm install -g @anthropic-ai/claude-code
This will make the claude
command available in your terminal.
Get a Liona access key
You’ll need a Liona access key to connect Claude Code to Liona:
- Sign in to your Liona dashboard
- Navigate to the Users section
- Find or create the user who needs Claude Code access
- Generate an access key for this user
Make sure the user has a policy that allows access to Claude models.
Configure Claude Code environment variables
Set up the required environment variables to direct Claude Code to use Liona:
# Add these to your shell profile (.bashrc, .zshrc, etc.)
export ANTHROPIC_API_KEY=your_liona_access_key_here
export ANTHROPIC_BASE_URL=https://api.liona.ai/v1/provider/anthropic
You can also set these variables for a single session:
ANTHROPIC_API_KEY=your_liona_access_key_here ANTHROPIC_BASE_URL=https://api.liona.ai/v1/provider/anthropic claude <command>
Verify the configuration
Test that Claude Code is correctly configured to work with Liona:
claude "Tell me a short joke"
If everything is configured correctly, you should receive a response from Claude through Liona.
Usage Tips
Project-Specific Configuration
For projects where you want to use specific settings, you can create a .env
file in your project directory:
# .env file in your project root
ANTHROPIC_API_KEY=your_liona_access_key_here
ANTHROPIC_BASE_URL=https://api.liona.ai/v1/provider/anthropic
Then, when you use Claude Code in that directory, it will pick up these settings automatically if you’re using a tool like direnv
or if you source the variables manually.
Command-Line Usage Examples
Here are some common ways to use Claude Code once it’s configured with Liona:
# Ask Claude a question
claude "What is quantum computing?"
# Get Claude to analyze code in a file
claude --file path/to/code.js
# Use Claude in interactive mode
claude
Troubleshooting
Rate Limit or Policy Errors
If you encounter an error message about rate limits or policy violations:
- Check your usage in the Liona dashboard
- Verify that the user has the correct policy assigned
- Consider increasing the limits in the policy if needed
Authentication Errors
If Claude Code can’t authenticate:
- Verify that the access key is correct and hasn’t expired
- Ensure the
ANTHROPIC_API_KEY
environment variable is set correctly - Check that the
ANTHROPIC_BASE_URL
is set tohttps://api.liona.ai/v1/provider/anthropic
Model Availability Errors
If you receive errors about model availability:
- Make sure the Claude provider is properly set up in your Liona dashboard
- Verify that the policy assigned to the user allows access to the requested model
Next Steps
Now that you’ve configured Claude Code to work with Liona, you might want to:
- Set up provider balancing to distribute requests across multiple keys
- Configure request caching to improve performance and reduce costs
- Enable request tracing for debugging and auditing