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:

Option 2: Configuration File

Create or edit the Claude Code configuration file:

Using Different Models

With Eden AI, you can use models from different providers:

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: Reload your shell:
source ~/.bashrc  # or ~/.zshrc

Custom Model Switching Script

Create a script to easily switch between models: 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):

Timeout Configuration

Adjust timeouts for longer requests:

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:

Next Steps