# Claude API Actor – BYOK Anthropic Claude AI Proxy for Apify (`hgservices/claude-api-actor`) Actor

Call Anthropic's Claude API directly from any Apify Actor or automation workflow. This Actor is a lightweight, BYOK (Bring Your Own Key) proxy that lets you integrate Claude AI, including Opus, Sonnet, and Haiku, into your Apify scraping pipelines, data extraction workflows, and AI automation tasks

- **URL**: https://apify.com/hgservices/claude-api-actor.md
- **Developed by:** [Harish Garg](https://apify.com/hgservices) (community)
- **Categories:** AI, Automation, Developer tools
- **Stats:** 29 total users, 6 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: 5.00 out of 5 stars

## Pricing

from $1.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## Claude API Actor – BYOK Anthropic Claude AI Proxy for Apify

Run Anthropic's Claude API directly from any Apify Actor or automation workflow. This Actor is a lightweight, BYOK (Bring Your Own Key) proxy that lets you integrate Claude AI — including Claude Opus, Claude Sonnet, and Claude Haiku — into your Apify scraping pipelines, data extraction workflows, and AI automation tasks without installing extra libraries or managing HTTP clients.

**Perfect for:** web scraping + AI analysis, content classification, data extraction, LLM-powered automation, and multi-Actor AI pipelines on Apify.

---

### Why Use This Claude API Apify Integration?

Most Apify scraping workflows need an AI step — classifying scraped content, extracting structured data, summarizing text, or generating output. Setting up the Anthropic SDK in every Actor is repetitive and slow. This Actor solves that:

- **Call Claude from any Apify Actor** — no Anthropic SDK needed in your own code
- **BYOK** — use your own Anthropic API key; you're billed directly by Anthropic
- **All Claude models supported** — Opus 4.x, Sonnet 4.x, Haiku (latest versions)
- **Flexible API key storage** — pass per-run or store persistently in Apify Key-Value Store
- **Drop-in AI step** for multi-Actor Apify workflows

---

### How to Call Claude API from Apify – Setup

#### Step 1: Get an Anthropic API Key

Sign up at [console.anthropic.com](https://console.anthropic.com/) and generate an API key. You will be billed by Anthropic based on your usage — this Actor does not add any markup.

#### Step 2: Store or Provide Your Anthropic API Key

You have two options:

**Option A: Pass it directly in the input (per-run, simplest)**

Include `anthropicApiKey` in your JSON input. No configuration needed — works immediately.

**Option B: Store it in Apify Key-Value Store (recommended for recurring use)**

1. Go to **Apify Console → Storage → Key-Value Stores**
2. Open the Actor's default Key-Value Store (auto-created on first run)
3. Add a record with key: `ANTHROPIC_API_KEY` and your Anthropic API key as the value

Key resolution order:
1. `anthropicApiKey` in input (if provided)
2. `ANTHROPIC_API_KEY` in default Key-Value Store
3. Error with clear message if neither is found

---

### Input Schema

| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| `messages` | `array` | ✅ Yes | — | Messages array in standard Anthropic API format |
| `anthropicApiKey` | `string` | ❌ No | — | Your Anthropic API key (or use KVS) |
| `model` | `string` | ❌ No | `claude-sonnet-4-6` | Claude model to use |
| `system` | `string` | ❌ No | — | System prompt |
| `max_tokens` | `integer` | ❌ No | `1024` | Max tokens to generate |
| `temperature` | `number` | ❌ No | `1.0` | Response randomness (0.0–1.0) |

#### Example Input

```json
{
  "messages": [
    {
      "role": "user",
      "content": "Summarize the following product reviews and identify the top 3 complaints."
    }
  ],
  "model": "claude-sonnet-4-6",
  "max_tokens": 1024,
  "system": "You are a helpful product analyst."
}
````

***

### Which Claude Model Should I Use?

| Model | Speed | Cost | Best For |
|---|---|---|---|
| `claude-opus-476` | Slowest | Highest | Complex reasoning, long-form analysis, highest quality output |
| `claude-sonnet-4-6` | Balanced | Medium | Default choice — best balance of speed and intelligence |
| `claude-haiku-4-5` | Fastest | Lowest | High-volume tasks: classification, extraction, summarization |

**Recommendation:** Start with `claude-sonnet-4-6`. Switch to Haiku for scale, Opus for quality-critical tasks.

***

### Output

The Actor returns the full Anthropic API JSON response, saved to:

- The **default Dataset** (one record per run)
- The `OUTPUT` key in the **default Key-Value Store** (for direct actor-to-actor access)

#### Example Output

```json
{
  "id": "msg_01XyZ...",
  "type": "message",
  "role": "assistant",
  "content": [
    {
      "type": "text",
      "text": "The top 3 complaints are: 1) slow delivery..."
    }
  ],
  "model": "claude-sonnet-4-6",
  "usage": {
    "input_tokens": 34,
    "output_tokens": 218
  }
}
```

***

### Integrate Claude into Apify Workflows – Actor-to-Actor Usage

The most powerful use case: calling this Claude API Actor from inside another Apify Actor to add AI processing to your scraping or automation pipeline.

#### JavaScript / Node.js Example

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });

// Call Claude API Actor from your own Apify Actor
const run = await client.actor('YOUR_USERNAME/claude-api-actor').call({
  messages: [
    {
      role: 'user',
      content: `Classify this product review as positive, negative, or neutral: "${reviewText}"`
    }
  ],
  model: 'claude-haiku-4-5-20251001',
  max_tokens: 128
});

// Read Claude's response
const { items } = await client.dataset(run.defaultDatasetId).listItems();
const text = items[0].content[0].text;
```

#### Python Example

```python
from apify_client import ApifyClient

client = ApifyClient(token=os.environ["APIFY_TOKEN"])

## Call Claude API Actor from your Apify scraping pipeline
run = client.actor("YOUR_USERNAME/claude-api-actor").call(run_input={
    "messages": [
        {
            "role": "user",
            "content": f"Extract the price and product name from this text: {scraped_text}"
        }
    ],
    "model": "claude-sonnet-4-6",
    "max_tokens": 256
})

items = client.dataset(run["defaultDatasetId"]).list_items().items
text = items[0]["content"][0]["text"]
```

***

### Common Use Cases

- **Web scraping + AI analysis** — scrape product pages, pass content to Claude for structured extraction
- **Content classification** — classify scraped articles, reviews, or listings at scale
- **Data extraction from unstructured text** — pull prices, names, dates from raw HTML or text
- **LLM-powered automation pipelines** — chain multiple Apify Actors with Claude as the AI reasoning step
- **Summarization** — summarize large scraped datasets before storing or exporting
- **Sentiment analysis** — analyze customer reviews, social media posts, or feedback at Apify scale

***

### Error Reference

| Error | Cause | Fix |
|---|---|---|
| `No API key found` | Key missing from both input and KVS | Add `anthropicApiKey` to input or set up KVS |
| `401 Unauthorized` | Invalid or expired Anthropic API key | Regenerate key at console.anthropic.com |
| `400 Bad Request` | Invalid model name or malformed messages | Check model name against the table above |
| `429 Too Many Requests` | Anthropic rate limit hit | Reduce request frequency or upgrade Anthropic plan |

***

### Frequently Asked Questions

**Is my Anthropic API key secure?**
Yes. Store your key in the Apify Key-Value Store rather than passing it in every input. It is encrypted at rest by Apify and never logged by this Actor.

**Which Claude model should I use for web scraping workflows?**
Use `claude-haiku-4-5-20251001` for high-volume, simple extraction tasks. Use `claude-sonnet-4-6` for more complex analysis. Reserve `claude-opus-4-6` for tasks that require maximum reasoning quality.

**Can I use this Actor without knowing the Anthropic API?**
Yes. The input format mirrors the official Anthropic API, but you don't need to understand HTTP clients or authentication — just provide your key and messages.

**Does this Actor cost anything beyond Anthropic's API fees?**
You pay Apify's standard Actor compute costs and Anthropic's API usage fees directly. This Actor does not add any markup.

**What's the difference between passing the API key in input vs Key-Value Store?**
Input is simpler for one-off runs. Key-Value Store is better for recurring workflows — store once, never repeat it in your input JSON again.

# Actor input Schema

## `anthropicApiKey` (type: `string`):

Your Anthropic API key from console.anthropic.com.

## `model` (type: `string`):

The Claude model to use.

## `userMessage` (type: `string`):

The message to send to Claude.

## `system` (type: `string`):

System prompt to guide Claude's behavior.

## `max_tokens` (type: `integer`):

The maximum number of tokens to generate before stopping.

## `temperature` (type: `number`):

Amount of randomness injected into the response. Ranges from 0.0 to 1.0.

## Actor input object example

```json
{
  "model": "claude-opus-4-7",
  "userMessage": "Hello",
  "system": "You are a helpful assistant.",
  "max_tokens": 1024,
  "temperature": 1
}
```

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "userMessage": "Hello",
    "system": "You are a helpful assistant."
};

// Run the Actor and wait for it to finish
const run = await client.actor("hgservices/claude-api-actor").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "userMessage": "Hello",
    "system": "You are a helpful assistant.",
}

# Run the Actor and wait for it to finish
run = client.actor("hgservices/claude-api-actor").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "userMessage": "Hello",
  "system": "You are a helpful assistant."
}' |
apify call hgservices/claude-api-actor --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=hgservices/claude-api-actor",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "openapi": "3.0.1",
    "info": {
        "title": "Claude API Actor – BYOK Anthropic Claude AI Proxy for Apify",
        "description": "Call Anthropic's Claude API directly from any Apify Actor or automation workflow. This Actor is a lightweight, BYOK (Bring Your Own Key) proxy that lets you integrate Claude AI, including Opus, Sonnet, and Haiku, into your Apify scraping pipelines, data extraction workflows, and AI automation tasks",
        "version": "0.2",
        "x-build-id": "CCTBUkSynke2MTTrv"
    },
    "servers": [
        {
            "url": "https://api.apify.com/v2"
        }
    ],
    "paths": {
        "/acts/hgservices~claude-api-actor/run-sync-get-dataset-items": {
            "post": {
                "operationId": "run-sync-get-dataset-items-hgservices-claude-api-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        },
        "/acts/hgservices~claude-api-actor/runs": {
            "post": {
                "operationId": "runs-sync-hgservices-claude-api-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor and returns information about the initiated run in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK",
                        "content": {
                            "application/json": {
                                "schema": {
                                    "$ref": "#/components/schemas/runsResponseSchema"
                                }
                            }
                        }
                    }
                }
            }
        },
        "/acts/hgservices~claude-api-actor/run-sync": {
            "post": {
                "operationId": "run-sync-hgservices-claude-api-actor",
                "x-openai-isConsequential": false,
                "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
                "tags": [
                    "Run Actor"
                ],
                "requestBody": {
                    "required": true,
                    "content": {
                        "application/json": {
                            "schema": {
                                "$ref": "#/components/schemas/inputSchema"
                            }
                        }
                    }
                },
                "parameters": [
                    {
                        "name": "token",
                        "in": "query",
                        "required": true,
                        "schema": {
                            "type": "string"
                        },
                        "description": "Enter your Apify token here"
                    }
                ],
                "responses": {
                    "200": {
                        "description": "OK"
                    }
                }
            }
        }
    },
    "components": {
        "schemas": {
            "inputSchema": {
                "type": "object",
                "required": [
                    "anthropicApiKey",
                    "userMessage"
                ],
                "properties": {
                    "anthropicApiKey": {
                        "title": "Anthropic API Key",
                        "type": "string",
                        "description": "Your Anthropic API key from console.anthropic.com."
                    },
                    "model": {
                        "title": "Model",
                        "enum": [
                            "claude-opus-4-7",
                            "claude-sonnet-4-6",
                            "claude-haiku-4-5"
                        ],
                        "type": "string",
                        "description": "The Claude model to use.",
                        "default": "claude-opus-4-7"
                    },
                    "userMessage": {
                        "title": "User Message",
                        "type": "string",
                        "description": "The message to send to Claude.",
                        "default": "Hello"
                    },
                    "system": {
                        "title": "System Prompt",
                        "type": "string",
                        "description": "System prompt to guide Claude's behavior.",
                        "default": "You are a helpful assistant."
                    },
                    "max_tokens": {
                        "title": "Max Tokens",
                        "minimum": 1,
                        "type": "integer",
                        "description": "The maximum number of tokens to generate before stopping.",
                        "default": 1024
                    },
                    "temperature": {
                        "title": "Temperature",
                        "minimum": 0,
                        "maximum": 1,
                        "type": "number",
                        "description": "Amount of randomness injected into the response. Ranges from 0.0 to 1.0.",
                        "default": 1
                    }
                }
            },
            "runsResponseSchema": {
                "type": "object",
                "properties": {
                    "data": {
                        "type": "object",
                        "properties": {
                            "id": {
                                "type": "string"
                            },
                            "actId": {
                                "type": "string"
                            },
                            "userId": {
                                "type": "string"
                            },
                            "startedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "finishedAt": {
                                "type": "string",
                                "format": "date-time",
                                "example": "2025-01-08T00:00:00.000Z"
                            },
                            "status": {
                                "type": "string",
                                "example": "READY"
                            },
                            "meta": {
                                "type": "object",
                                "properties": {
                                    "origin": {
                                        "type": "string",
                                        "example": "API"
                                    },
                                    "userAgent": {
                                        "type": "string"
                                    }
                                }
                            },
                            "stats": {
                                "type": "object",
                                "properties": {
                                    "inputBodyLen": {
                                        "type": "integer",
                                        "example": 2000
                                    },
                                    "rebootCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "restartCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "resurrectCount": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "computeUnits": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "options": {
                                "type": "object",
                                "properties": {
                                    "build": {
                                        "type": "string",
                                        "example": "latest"
                                    },
                                    "timeoutSecs": {
                                        "type": "integer",
                                        "example": 300
                                    },
                                    "memoryMbytes": {
                                        "type": "integer",
                                        "example": 1024
                                    },
                                    "diskMbytes": {
                                        "type": "integer",
                                        "example": 2048
                                    }
                                }
                            },
                            "buildId": {
                                "type": "string"
                            },
                            "defaultKeyValueStoreId": {
                                "type": "string"
                            },
                            "defaultDatasetId": {
                                "type": "string"
                            },
                            "defaultRequestQueueId": {
                                "type": "string"
                            },
                            "buildNumber": {
                                "type": "string",
                                "example": "1.0.0"
                            },
                            "containerUrl": {
                                "type": "string"
                            },
                            "usage": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "integer",
                                        "example": 1
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            },
                            "usageTotalUsd": {
                                "type": "number",
                                "example": 0.00005
                            },
                            "usageUsd": {
                                "type": "object",
                                "properties": {
                                    "ACTOR_COMPUTE_UNITS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATASET_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "KEY_VALUE_STORE_WRITES": {
                                        "type": "number",
                                        "example": 0.00005
                                    },
                                    "KEY_VALUE_STORE_LISTS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_READS": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "REQUEST_QUEUE_WRITES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_INTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "DATA_TRANSFER_EXTERNAL_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                                        "type": "integer",
                                        "example": 0
                                    },
                                    "PROXY_SERPS": {
                                        "type": "integer",
                                        "example": 0
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
