Skip to main content

OpenAI API Integration

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

Prerequisites

Installation

pip install openai

Basic Usage

from openai import OpenAI

client = OpenAI(api_key="your-openai-api-key")

response = client.responses.create(
model="gpt-4o",
tools=[
{
"type": "mcp",
"server_label": "jsoncut",
"server_url": "https://mcp.jsoncut.com/mcp",
"require_approval": "never",
"headers": {
"x-api-key": "your-jsoncut-api-key"
}
}
],
input="Create a social media image with the text 'New Product Launch' on a gradient background.",
)

print(response.output_text)
warning

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

Configuration Options

{
"type": "mcp", # Required: Must be "mcp"
"server_label": "jsoncut", # Label for the MCP server
"server_url": "https://mcp.jsoncut.com/mcp", # MCP server endpoint
"require_approval": "never", # "never", "always", or "auto"
"headers": {
"x-api-key": "your-jsoncut-api-key" # Your JsonCut API key
}
}

Approval Modes:

  • "never" - AI uses tools without approval (recommended for automation)
  • "always" - AI asks for approval before using tools
  • "auto" - AI decides when to ask for approval

Examples

Example 1: Generate Social Media Image

from openai import OpenAI

client = OpenAI(api_key="your-openai-api-key")

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

response = client.responses.create(
model="gpt-4o",
tools=[
{
"type": "mcp",
"server_label": "jsoncut",
"server_url": "https://mcp.jsoncut.com/mcp",
"require_approval": "never",
"headers": {
"x-api-key": "your-jsoncut-api-key"
}
}
],
input=f"Create a promotional image with title '{image_data['title']}' "
f"and discount text '{image_data['discount']}' "
f"on a {image_data['background']} background.",
)

print(response.output_text)

Example 2: Batch Image Generation

from openai import OpenAI

client = OpenAI(api_key="your-openai-api-key")

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

for product in products:
response = client.responses.create(
model="gpt-4o",
tools=[
{
"type": "mcp",
"server_label": "jsoncut",
"server_url": "https://mcp.jsoncut.com/mcp",
"require_approval": "never",
"headers": {
"x-api-key": "your-jsoncut-api-key"
}
}
],
input=f"Generate a product showcase image for {product}. "
f"Include product name, features, and a call-to-action button.",
)

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

Troubleshooting

Authentication Errors

Solutions:

  • Verify your JsonCut API key in the dashboard
  • Check the header name is x-api-key
  • Ensure no extra spaces in the key
  • Verify the key hasn't expired

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