Skip to main content

Anthropic API Integration

Use the JsonCut MCP server with Anthropic's API to generate images and videos programmatically.

Prerequisites

Installation

pip install anthropic

Basic Usage

import anthropic

client = anthropic.Anthropic(api_key="your-anthropic-api-key")

response = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
messages=[
{
"role": "user",
"content": "Create a social media image with the text 'New Product Launch' on a gradient background."
}
],
mcp_servers=[
{
"type": "url",
"url": "https://mcp.jsoncut.com/mcp",
"name": "jsoncut",
"authorization_token": "your-jsoncut-api-key"
}
],
extra_headers={
"anthropic-beta": "mcp-client-2025-04-04"
}
)

print(response.content)
warning

Replace your-anthropic-api-key and your-jsoncut-api-key with your actual API keys.

Configuration Options

{
"type": "url", # Required: Must be "url"
"url": "https://mcp.jsoncut.com/mcp", # MCP server endpoint
"name": "jsoncut", # Name for the MCP server
"authorization_token": "your-jsoncut-api-key" # Your JsonCut API key
}

Important:

  • The extra_headers with anthropic-beta: mcp-client-2025-04-04 is required for MCP support
  • Use client.beta.messages.create() instead of the regular messages.create()
  • The authorization token is your JsonCut API key

Examples

Example 1: Generate Social Media Image

import anthropic

client = anthropic.Anthropic(api_key="your-anthropic-api-key")

image_data = {
"title": "Summer Sale",
"discount": "50% OFF",
"background": "gradient"
}

response = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
messages=[
{
"role": "user",
"content": f"Create a promotional image with title '{image_data['title']}' "
f"and discount text '{image_data['discount']}' "
f"on a {image_data['background']} background."
}
],
mcp_servers=[
{
"type": "url",
"url": "https://mcp.jsoncut.com/mcp",
"name": "jsoncut",
"authorization_token": "your-jsoncut-api-key"
}
],
extra_headers={
"anthropic-beta": "mcp-client-2025-04-04"
}
)

print(response.content)

Example 2: Batch Image Generation

import anthropic

client = anthropic.Anthropic(api_key="your-anthropic-api-key")

products = ["Product A", "Product B", "Product C"]

for product in products:
response = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
messages=[
{
"role": "user",
"content": f"Generate a product showcase image for {product}. "
f"Include product name, features, and a call-to-action button."
}
],
mcp_servers=[
{
"type": "url",
"url": "https://mcp.jsoncut.com/mcp",
"name": "jsoncut",
"authorization_token": "your-jsoncut-api-key"
}
],
extra_headers={
"anthropic-beta": "mcp-client-2025-04-04"
}
)

print(f"Generated image for {product}: {response.content}")

Troubleshooting

Authentication Errors

Solutions:

  • Verify your JsonCut API key in the dashboard
  • Check the authorization token is set correctly
  • Ensure no extra spaces in the key
  • Verify the key hasn't expired

Beta API Errors

Solutions:

  • Ensure you're using client.beta.messages.create()
  • Verify the extra_headers includes anthropic-beta: mcp-client-2025-04-04
  • Check you have access to the beta API features

Connection Issues

Solutions:

  • Verify the URL: https://mcp.jsoncut.com/mcp
  • Check your internet connection
  • Ensure firewall allows the connection

Rate Limiting

Solutions:

  • Check your JsonCut plan limits in the dashboard
  • Implement exponential backoff in your code
  • Monitor your usage