Skip to main content

Claude Code

Configure Claude Code CLI to use Eden AI’s multi-provider backend for enhanced flexibility and cost savings.

Overview

Claude Code is Anthropic’s official CLI tool for AI-powered coding assistance. By default, it uses Anthropic’s API, but you can configure it to use Eden AI for:
  • Multi-provider access: Use GPT-4, Gemini, or other models alongside Claude
  • Cost optimization: Leverage Eden AI’s competitive pricing
  • Provider redundancy: Automatic failover if one provider is down

Prerequisites

Configuration

Claude Code can be configured to use custom API endpoints through environment variables or configuration files.

Option 1: Environment Variables

Set environment variables before running Claude Code:
# Set Eden AI as the API endpoint
export ANTHROPIC_API_KEY="YOUR_EDEN_AI_API_KEY"
export ANTHROPIC_BASE_URL="https://api.edenai.run/v3/llm"

# Run Claude Code
claude-code

Option 2: Configuration File

Create or edit the Claude Code configuration file:
{
  "api_key": "YOUR_EDEN_AI_API_KEY",
  "base_url": "https://api.edenai.run/v3/llm",
  "model": "anthropic/claude-3-5-sonnet-20241022"
}

Using Different Models

With Eden AI, you can use models from different providers:
# Use Claude 3.5 Sonnet (default)
export ANTHROPIC_MODEL="anthropic/claude-3-5-sonnet-20241022"
claude-code

# Use GPT-4
export ANTHROPIC_MODEL="openai/gpt-4"
claude-code

# Use Gemini Pro
export ANTHROPIC_MODEL="google/gemini-pro"
claude-code

Model Format

When using Eden AI with Claude Code, use the provider/model format:

Anthropic Models

  • anthropic/claude-3-5-sonnet-20241022 (recommended)
  • anthropic/claude-3-opus-20240229
  • anthropic/claude-3-sonnet-20240229
  • anthropic/claude-3-haiku-20240307

OpenAI Models

  • openai/gpt-4
  • openai/gpt-4-turbo
  • openai/gpt-4o

Google Models

  • google/gemini-pro
  • google/gemini-1.5-pro

Permanent Configuration

Make the configuration permanent by adding to your shell profile:
# Eden AI configuration for Claude Code
export ANTHROPIC_API_KEY="YOUR_EDEN_AI_API_KEY"
export ANTHROPIC_BASE_URL="https://api.edenai.run/v3/llm"
export ANTHROPIC_MODEL="anthropic/claude-3-5-sonnet-20241022"
Reload your shell:
source ~/.bashrc  # or ~/.zshrc

Custom Model Switching Script

Create a script to easily switch between models:
#!/bin/bash

case "$1" in
  claude)
    export ANTHROPIC_MODEL="anthropic/claude-3-5-sonnet-20241022"
    echo "Switched to Claude 3.5 Sonnet"
    ;;
  gpt4)
    export ANTHROPIC_MODEL="openai/gpt-4"
    echo "Switched to GPT-4"
    ;;
  gemini)
    export ANTHROPIC_MODEL="google/gemini-pro"
    echo "Switched to Gemini Pro"
    ;;
  *)
    echo "Usage: source switch-model.sh [claude|gpt4|gemini]"
    ;;
esac

claude-code
Usage:
chmod +x switch-model.sh
source switch-model.sh claude   # Use Claude
source switch-model.sh gpt4     # Use GPT-4
source switch-model.sh gemini   # Use Gemini

Features

Code Generation

Claude Code can generate code in any language with Eden AI:
claude-code "Create a Python function to fetch data from an API"

Code Review

Review and improve existing code:
claude-code "Review this code for security issues" < myfile.py

Refactoring

Refactor code with context awareness:
claude-code "Refactor this function to use async/await" < myfile.js

Documentation

Generate documentation:
claude-code "Add docstrings to all functions" < mymodule.py

Advanced Configuration

Custom Headers

If you need to pass custom headers (e.g., for analytics):
{
  "api_key": "YOUR_EDEN_AI_API_KEY",
  "base_url": "https://api.edenai.run/v3/llm",
  "model": "anthropic/claude-3-5-sonnet-20241022",
  "headers": {
    "X-Custom-Header": "value"
  }
}

Timeout Configuration

Adjust timeouts for longer requests:
{
  "api_key": "YOUR_EDEN_AI_API_KEY",
  "base_url": "https://api.edenai.run/v3/llm",
  "timeout": 120000
}

Troubleshooting

Authentication Errors

If you see authentication errors:
  1. Verify your Eden AI API key is correct
  2. Check that the ANTHROPIC_API_KEY environment variable is set
  3. Ensure there are no trailing spaces in your API key
# Test your API key
curl -X POST https://api.edenai.run/v3/llm/chat/completions \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-3-5-sonnet-20241022",
    "messages": [{"role": "user", "content": "test"}],
    "stream": true
  }'

Model Not Found

Ensure you’re using the correct model format:
# Correct
anthropic/claude-3-5-sonnet-20241022

# Incorrect
claude-3-5-sonnet-20241022

Connection Issues

If you experience connection issues:
  1. Check your internet connection
  2. Verify the base URL is correct: https://api.edenai.run/v3/llm
  3. Check Eden AI status: https://app-edenai.instatus.com

Cost Tracking

Monitor your Eden AI usage through the dashboard:
# View your current usage
curl https://api.edenai.run/v3/cost-management/usage \
  -H "Authorization: Bearer YOUR_API_KEY"

Best Practices

1. Use Appropriate Models

Choose models based on task complexity:
  • Simple tasks: anthropic/claude-3-haiku-20240307 (fast, cost-effective)
  • Complex reasoning: anthropic/claude-3-5-sonnet-20241022 (best balance)
  • Maximum capability: anthropic/claude-3-opus-20240229 (most powerful)

2. Leverage Multiple Providers

Test different providers for different tasks:
  • Code generation: GPT-4 or Claude
  • Explanation: Claude or Gemini
  • Quick tasks: Haiku or GPT-3.5

3. Monitor Costs

Regularly check your Eden AI dashboard to track spending and optimize model selection.

Integration with Git

Use Claude Code in Git hooks for automated code review:
#!/bin/bash

# Export Eden AI configuration
export ANTHROPIC_API_KEY="YOUR_EDEN_AI_API_KEY"
export ANTHROPIC_BASE_URL="https://api.edenai.run/v3/llm"

# Get changed files
changed_files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.py$')

if [ -n "$changed_files" ]; then
  echo "Reviewing changed Python files..."
  for file in $changed_files; do
    claude-code "Quick security review" < "$file"
  done
fi

Next Steps