Skip to content

Anthropic (Claude) Setup Guide

What You'll Learn

How to connect Anthropic's Claude models to RunForge for high-quality AI with strong reasoning capabilities.

Why Choose Anthropic/Claude?

Excellent Reasoning

  • Strong analytical capabilities: Great for complex problem-solving
  • Nuanced responses: Better at understanding context and subtlety
  • Reliable performance: Consistent quality across different tasks
  • Safety-focused: Built with strong safety guidelines

Competitive Pricing

  • Cost-effective models: Claude Haiku competes well on price
  • Good value: Strong performance-to-cost ratio
  • Transparent pricing: Clear, predictable costs
  • No hidden fees: Pay only for what you use

Developer Experience

  • Large context windows: Handle longer conversations and documents
  • OpenAI-compatible API: Easy integration if you're used to OpenAI
  • Good documentation: Clear guides and examples
  • Reliable service: Strong uptime and performance

Before You Start

Step 1: Create Your Anthropic Account

Sign Up

  1. Go to console.anthropic.com
  2. Click "Sign Up"
  3. Enter your information: Email, name, and password
  4. Verify your email if required
  5. Complete any additional verification steps

Add Credits

  1. Sign in to your Anthropic console
  2. Go to "Billing" or "Credits"
  3. Click "Add Credits" or "Purchase Credits"
  4. Choose amount: Start with $20-50 for testing
  5. Complete payment and verify credits appear

Step 2: Generate API Key

Create Your Key

  1. Go to "API Keys" in your Anthropic console
  2. Click "Create Key"
  3. Configure the key:
  4. Name: "RunForge Production" or similar
  5. Permissions: Full access (or customize as needed)
  6. Rate limits: Set if desired (optional)
  7. Click "Create"
  8. Copy the key immediately and store it securely

Security Notes

  • Never share your API key publicly
  • Use environment variables in your applications
  • Set spending alerts in your Anthropic account
  • Rotate keys every 3-6 months for security

Step 3: Add Anthropic to RunForge

  1. Open RunForge and sign in
  2. Select your project from the project dropdown
  3. Go to Settings → API Keys

Configure Anthropic

  1. Click "Add API Key" or "Add Provider Key"
  2. Select "Anthropic" from the dropdown (or "Custom" if not listed)
  3. Fill out the form:
  4. Key Name: "Production Anthropic Key"
  5. API Key: Paste your Anthropic API key
  6. Base URL (if using Custom): https://api.anthropic.com
  7. Description: "Main Claude key for analysis tasks"
  8. Test the connection - RunForge will verify it works
  9. Save the configuration

Step 4: Configure Your Application

TypeScript/JavaScript Setup

Since Anthropic uses a different API format than OpenAI, you have two options:

Option A: Direct Anthropic SDK

npm install @anthropic-ai/sdk @runforge/sdk
import Anthropic from '@anthropic-ai/sdk';
import { RunForge } from '@runforge/sdk';

const anthropic = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY!
});

const runforge = new RunForge({
  apiKey: process.env.RUNFORGE_API_KEY!,
  projectId: process.env.RUNFORGE_PROJECT_ID!,
  endpoint: process.env.RUNFORGE_ENDPOINT!
});

async function generateResponse(userMessage: string) {
  const result = await runforge.track(
    { 
      experiment: 'claude-test',
      provider: 'anthropic'
    },
    () => anthropic.messages.create({
      model: 'claude-3-haiku-20240307',
      max_tokens: 500,
      temperature: 0.7,
      messages: [
        { role: 'user', content: userMessage }
      ]
    })
  );

  return result.content[0].text;
}

Option B: OpenAI SDK with Anthropic (via OpenRouter or compatible endpoint)

npm install openai @runforge/sdk
import OpenAI from 'openai';
import { RunForge } from '@runforge/sdk';

// If using a compatibility layer like OpenRouter
const openai = new OpenAI({
  apiKey: process.env.OPENROUTER_API_KEY!, // or compatible service key
  baseURL: 'https://openrouter.ai/api/v1' // or compatible endpoint
});

const runforge = new RunForge({
  apiKey: process.env.RUNFORGE_API_KEY!,
  projectId: process.env.RUNFORGE_PROJECT_ID!,
  endpoint: process.env.RUNFORGE_ENDPOINT!
});

async function generateResponse(userMessage: string) {
  const result = await runforge.track(
    { 
      experiment: 'claude-via-openrouter',
      provider: 'anthropic'
    },
    () => openai.chat.completions.create({
      model: 'anthropic/claude-3-haiku', // Note: provider/model format for OpenRouter
      messages: [
        { role: 'system', content: 'You are a helpful assistant.' },
        { role: 'user', content: userMessage }
      ],
      temperature: 0.7,
      max_tokens: 500
    })
  );

  return result.choices[0].message.content;
}

Python Setup

Option A: Direct Anthropic SDK

pip install anthropic runforge
import os
import anthropic
from runforge import RunForge

client = anthropic.Anthropic(
    api_key=os.environ['ANTHROPIC_API_KEY']
)

rf = RunForge(
    api_key=os.environ['RUNFORGE_API_KEY'],
    project_id=os.environ['RUNFORGE_PROJECT_ID'],
    endpoint=os.environ['RUNFORGE_ENDPOINT']
)

def generate_response(user_message):
    result = rf.track(
        {
            "experiment": "claude-test",
            "provider": "anthropic"
        },
        lambda: client.messages.create(
            model="claude-3-haiku-20240307",
            max_tokens=500,
            temperature=0.7,
            messages=[
                {"role": "user", "content": user_message}
            ]
        )
    )

    return result.content[0].text

Option B: OpenAI SDK with Compatible Service

import os
from openai import OpenAI
from runforge import RunForge

# Using OpenRouter or similar compatibility layer
client = OpenAI(
    api_key=os.environ['OPENROUTER_API_KEY'],
    base_url='https://openrouter.ai/api/v1'
)

rf = RunForge(
    api_key=os.environ['RUNFORGE_API_KEY'],
    project_id=os.environ['RUNFORGE_PROJECT_ID'],
    endpoint=os.environ['RUNFORGE_ENDPOINT']
)

def generate_response(user_message):
    result = rf.track(
        {
            "experiment": "claude-via-openrouter", 
            "provider": "anthropic"
        },
        lambda: client.chat.completions.create(
            model="anthropic/claude-3-haiku",
            messages=[
                {"role": "system", "content": "You are a helpful assistant."},
                {"role": "user", "content": user_message}
            ],
            temperature=0.7,
            max_tokens=500
        )
    )

    return result.choices[0].message.content

Step 5: Understanding Claude Models

Claude 3 Haiku (Budget-Friendly)

  • Cost: ~$0.25/1M input tokens, ~$1.25/1M output tokens
  • Speed: Very fast (~1 second average)
  • Context: 200K tokens
  • Best for: Simple tasks, high-volume applications, quick responses
  • Quality: Good for most basic needs, efficient

Claude 3 Sonnet (Balanced)

  • Cost: ~$3/1M input tokens, ~$15/1M output tokens
  • Speed: Fast (~2 seconds average)
  • Context: 200K tokens
  • Best for: Most production applications, balanced performance
  • Quality: High quality reasoning and analysis

Claude 3 Opus (Premium)

  • Cost: ~$15/1M input tokens, ~$75/1M output tokens
  • Speed: Moderate (~3-4 seconds average)
  • Context: 200K tokens
  • Best for: Complex reasoning, research, creative writing, critical tasks
  • Quality: Top tier, most capable model

Model Selection Guide

Start with Claude 3 Haiku for: - Customer support chatbots - Content summarization - Simple Q&A systems - High-volume applications where cost matters

Upgrade to Claude 3 Sonnet for: - Complex analysis tasks - Creative content generation
- Professional writing assistance - Applications where quality is important

Use Claude 3 Opus only when: - Maximum quality is essential - Complex reasoning is required - Cost is less important than capability - You've tested and confirmed significant quality improvements

Step 6: Test Your Setup

Make Your First Call

Run your application code and verify:

In your application: - You get a coherent response from Claude - No authentication or API errors - Response format matches your expectations

In RunForge dashboard (within 30 seconds): - New request appears with correct model name - Cost information is recorded (may be estimated if using direct API) - Response time and success status logged

In Anthropic console: - Usage appears in your account dashboard - Credits are deducted appropriately

Troubleshooting Common Issues

Authentication errors: 1. Double-check your Anthropic API key is correct 2. Ensure your account has sufficient credits 3. Verify you haven't hit rate limits 4. Check that your key has the necessary permissions

Different response format: - Anthropic's direct API returns content[0].text instead of choices[0].message.content - Make sure your response parsing matches the API format you're using

Cost tracking issues: - Direct Anthropic API may require server-side cost calculation - Consider using through OpenRouter for exact cost tracking - Verify your RunForge setup is correctly configured

Claude Strengths and Use Cases

Analytical Tasks

Claude excels at: - Document analysis: Reviewing contracts, reports, research papers - Data interpretation: Making sense of complex information - Comparative analysis: Comparing options, pros/cons evaluation - Research assistance: Synthesizing information from multiple sources

Creative and Writing Tasks

Strong performance in: - Long-form content: Articles, blog posts, documentation - Creative writing: Stories, marketing copy, scripts - Technical writing: Clear explanations of complex topics - Editing and revision: Improving existing content

Reasoning and Problem-Solving

Particularly good at: - Multi-step reasoning: Breaking down complex problems - Logical analysis: Identifying flaws in arguments - Strategic thinking: Planning and decision-making assistance - Code analysis: Understanding and explaining code logic

Cost Optimization with Claude

Prompt Optimization

  • Be specific: Clear instructions reduce need for follow-up questions
  • Use examples: Show Claude the desired output format
  • Set context clearly: Avoid ambiguity that leads to longer responses
  • Limit scope: Focus on specific aspects rather than broad analysis

Model Selection Strategy

// Smart model routing based on task complexity
function selectClaudeModel(taskComplexity: 'simple' | 'medium' | 'complex') {
  switch (taskComplexity) {
    case 'simple':
      return 'claude-3-haiku-20240307';
    case 'medium':  
      return 'claude-3-sonnet-20240229';
    case 'complex':
      return 'claude-3-opus-20240229';
  }
}

// Usage example
const model = selectClaudeModel(determineComplexity(userRequest));

Batch Processing

Process multiple related items together:

const batchPrompt = `Please analyze these 3 customer reviews and provide insights:

Review 1: "${review1}"
Review 2: "${review2}" 
Review 3: "${review3}"

For each review, provide:
1. Sentiment (positive/negative/neutral)
2. Key concerns or praise
3. Actionable insights

Format as: Review 1: [analysis], Review 2: [analysis], etc.`;

Advanced Features

Large Context Windows

Take advantage of Claude's 200K token context:

// Processing entire documents
const result = await runforge.track(
  { experiment: 'document-analysis' },
  () => anthropic.messages.create({
    model: 'claude-3-sonnet-20240229',
    max_tokens: 2000,
    messages: [
      { 
        role: 'user', 
        content: `Please analyze this entire contract and highlight key risks and obligations:\n\n${entireContract}`
      }
    ]
  })
);

Multi-turn Conversations

Maintain context across multiple exchanges:

const conversationHistory = [
  { role: 'user', content: 'What are the main benefits of renewable energy?' },
  { role: 'assistant', content: 'Renewable energy offers several key benefits...' },
  { role: 'user', content: 'How do the costs compare to fossil fuels?' }
];

const result = await runforge.track(
  { experiment: 'conversation-analysis' },
  () => anthropic.messages.create({
    model: 'claude-3-haiku-20240307',
    max_tokens: 1000,
    messages: conversationHistory
  })
);

System Instructions

Guide Claude's behavior consistently:

const systemPrompt = `You are an expert business analyst. When reviewing documents:
1. Focus on financial implications
2. Identify potential risks  
3. Suggest actionable recommendations
4. Keep responses concise but thorough
5. Use bullet points for clarity`;

// Include system context in your messages
const result = await anthropic.messages.create({
  model: 'claude-3-sonnet-20240229',
  max_tokens: 1500,
  messages: [
    { role: 'user', content: `${systemPrompt}\n\nPlease analyze: ${document}` }
  ]
});

Monitoring and Optimization

Key Metrics to Track

  • Cost per analysis: Track efficiency for different task types
  • Quality consistency: Monitor output quality over time
  • Context utilization: How much of the large context window you're using
  • Response length: Optimize max_tokens based on actual needs
  1. Budget alerts: 80% of monthly Anthropic spend
  2. Quality degradation: If using automated quality scoring
  3. Usage spikes: Unusual increases in request volume
  4. Long response times: If responses are taking too long

Integration Best Practices

Error Handling

async function robustClaudeCall(prompt: string, retries = 3) {
  for (let i = 0; i < retries; i++) {
    try {
      return await runforge.track(
        { experiment: 'robust-claude', attempt: i + 1 },
        () => anthropic.messages.create({
          model: 'claude-3-haiku-20240307',
          max_tokens: 1000,
          messages: [{ role: 'user', content: prompt }]
        })
      );
    } catch (error) {
      if (i === retries - 1) throw error;
      await new Promise(resolve => setTimeout(resolve, 1000 * (i + 1))); // Exponential backoff
    }
  }
}

Response Validation

function validateClaudeResponse(response: any) {
  if (!response.content || response.content.length === 0) {
    throw new Error('Empty response from Claude');
  }

  const text = response.content[0].text;
  if (text.length < 10) {
    console.warn('Unusually short response from Claude');
  }

  return text;
}

Next Steps