DEV Community

Hommy
Hommy

Posted on

[JCAIGC]Create rich text styles

ADD_TEXT_STYLE API Interface Documentation

πŸ“‹ Table of Contents

πŸ”§ Interface Information

POST /openapi/capcut-mate/v1/add_text_style
Enter fullscreen mode Exit fullscreen mode

Function Description

Create rich text styles. This interface is used to create rich text styles with specific formatting, including keyword highlighting, color settings, font size adjustments, etc. It is suitable for video subtitle beautification, text highlighting, content emphasis, and other scenarios.

More Documentation

πŸ“– For more detailed documentation and tutorials, please visit: https://docs.jcaigc.cn

Request Parameters

Request Body (application/json)

Parameter Name Type Required Default Value Description
draft_url string βœ… - Target draft URL, format: https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=xxx
text_styles array βœ… - Rich text style list, supports creating multiple text styles at once

Text Style Object Structure

{
  "draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258",
  "text_styles": [
    {
      "element_id": "text_001",
      "keyword": "important",
      "style": {
        "color": "#FF6B35",
        "font_size": 24,
        "font_weight": "bold",
        "background_color": "#FFE5CC",
        "border_color": "#FF6B35",
        "border_width": 2,
        "padding": 8,
        "border_radius": 12
      },
      "apply_to": "keyword"
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

Text Style Parameter Description

Parameter Name Type Required Default Value Description
element_id string βœ… - Text element ID, used to identify the target text element
keyword string ❌ - Keyword, used to match specific text content
style object βœ… - Style configuration object
apply_to string ❌ "all" Application scope

Style Object Structure

Parameter Name Type Required Default Value Description
color string ❌ "#000000" Text color, supports hex color codes
font_size number ❌ 16 Font size, range: 8-72
font_weight string ❌ "normal" Font weight
background_color string ❌ "transparent" Background color
border_color string ❌ "transparent" Border color
border_width number ❌ 0 Border width, range: 0-10
padding number ❌ 0 Inner padding, range: 0-20
border_radius number ❌ 0 Border radius, range: 0-50
text_decoration string ❌ "none" Text decoration
text_shadow string ❌ "none" Text shadow
font_family string ❌ "system" Font family
line_height number ❌ 1.2 Line height, range: 0.8-3.0
letter_spacing number ❌ 0 Letter spacing, range: -5 to 20
text_align string ❌ "left" Text alignment

Apply Scope Options

Apply Scope Description Application Scenario
all Apply to all text Overall style modification
keyword Apply only to matching keywords Keyword highlighting
sentence Apply to sentences containing keywords Sentence emphasis
paragraph Apply to paragraphs containing keywords Paragraph highlighting

Font Weight Options

Font Weight Description Effect
normal Normal font weight Standard effect
bold Bold Emphasis effect
lighter Lighter Soft effect
bolder Extra bold Strong emphasis
100-900 Numeric weight Precise control

Text Decoration Options

Decoration Type Description
none No decoration
underline Underline
overline Overline
line_through Strikethrough
underline line_through Underline and strikethrough

Text Alignment Options

Alignment Description
left Left aligned
center Center aligned
right Right aligned
justify Justified

Text Shadow Options

{
  "text_shadow": "2px 2px 4px rgba(0,0,0,0.3)"
}
Enter fullscreen mode Exit fullscreen mode

Font Family Options

Font Family Description
system System default font
serif Serif font
sans_serif Sans-serif font
monospace Monospace font
cursive Cursive font
fantasy Fantasy font

Response Format

Success Response (200)

{
  "draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258",
  "tip_url": "https://help.assets.jcaigc.cn/draft-usage"
}
Enter fullscreen mode Exit fullscreen mode

Response Field Description

Field Name Type Description
draft_url string Draft URL after creating text styles, same as the request URL
tip_url string Draft usage help document URL

Error Response (4xx/5xx)

{
  "detail": "Error message description"
}
Enter fullscreen mode Exit fullscreen mode

Usage Examples

cURL Example

1. Keyword highlighting

curl -X POST https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/add_text_style \
  -H "Content-Type: application/json" \
  -d '{
    "draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258",
    "text_styles": [
      {
        "element_id": "text_001",
        "keyword": "important",
        "style": {
          "color": "#FF6B35",
          "font_size": 24,
          "font_weight": "bold",
          "background_color": "#FFE5CC",
          "border_color": "#FF6B35",
          "border_width": 2,
          "padding": 8,
          "border_radius": 12
        },
        "apply_to": "keyword"
      }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

2. Multiple text styles

curl -X POST https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/add_text_style \
  -H "Content-Type: application/json" \
  -d '{
    "draft_url": "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258",
    "text_styles": [
      {
        "element_id": "text_001",
        "keyword": "title",
        "style": {
          "color": "#2E86AB",
          "font_size": 32,
          "font_weight": "bold",
          "text_align": "center",
          "text_shadow": "2px 2px 4px rgba(0,0,0,0.3)"
        },
        "apply_to": "keyword"
      },
      {
        "element_id": "text_001",
        "keyword": "warning",
        "style": {
          "color": "#F24236",
          "font_size": 20,
          "font_weight": "bold",
          "background_color": "#FFE5E5",
          "border_color": "#F24236",
          "border_width": 3,
          "border_radius": 8,
          "padding": 6
        },
        "apply_to": "keyword"
      },
      {
        "element_id": "text_002",
        "style": {
          "color": "#4ECDC4",
          "font_size": 18,
          "font_family": "sans_serif",
          "line_height": 1.5,
          "letter_spacing": 1
        },
        "apply_to": "all"
      }
    ]
  }'
Enter fullscreen mode Exit fullscreen mode

JavaScript Example

// Create text style function
const addTextStyle = async (draftUrl, textStyleList) => {
  const response = await fetch('/openapi/capcut-mate/v1/add_text_style', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      draft_url: draftUrl,
      text_styles: textStyleList
    })
  });
  return response.json();
};

// Usage example
(async () => {
  const draftUrl = "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258";

  const textStyleList = [
    {
      element_id: "text_001",
      keyword: "important",
      style: {
        color: "#FF6B35",
        font_size: 24,
        font_weight: "bold",
        background_color: "#FFE5CC",
        border_color: "#FF6B35",
        border_width: 2,
        padding: 8,
        border_radius: 12
      },
      apply_to: "keyword"
    },
    {
      element_id: "text_002",
      style: {
        color: "#4ECDC4",
        font_size: 18,
        font_family: "sans_serif",
        line_height: 1.5,
        letter_spacing: 1
      },
      apply_to: "all"
    }
  ];

  const result = await addTextStyle(draftUrl, textStyleList);
  console.log('Text styles created successfully:', result);
})();
Enter fullscreen mode Exit fullscreen mode

Python Example

import requests

def add_text_style(draft_url, text_style_list):
    """Create rich text styles"""
    response = requests.post(
        'https://api.assets.jcaigc.cn/openapi/capcut-mate/v1/add_text_style',
        headers={'Content-Type': 'application/json'},
        json={
            "draft_url": draft_url,
            "text_styles": text_style_list
        }
    )
    return response.json()

# Usage example
draft_url = "https://capcut-mate.jcaigc.cn/openapi/capcut-mate/v1/get_draft?draft_id=2025092811473036584258"

text_style_list = [
    {
        "element_id": "text_001",
        "keyword": "important",
        "style": {
            "color": "#FF6B35",
            "font_size": 24,
            "font_weight": "bold",
            "background_color": "#FFE5CC",
            "border_color": "#FF6B35",
            "border_width": 2,
            "padding": 8,
            "border_radius": 12
        },
        "apply_to": "keyword"
    },
    {
        "element_id": "text_002",
        "style": {
            "color": "#4ECDC4",
            "font_size": 18,
            "font_family": "sans_serif",
            "line_height": 1.5,
            "letter_spacing": 1
        },
        "apply_to": "all"
    }
]

result = add_text_style(draft_url, text_style_list)
print(f"Text styles created successfully: {result['draft_url']}")
Enter fullscreen mode Exit fullscreen mode

Error Code Description

Error Code Error Message Description Solution
400 draft_url is required Missing draft URL parameter Provide a valid draft_url
400 text_styles parameter must be an array text_styles parameter format error Ensure text_styles is an array type
400 element_id cannot be empty Element ID cannot be empty Provide a valid element_id
400 Invalid color format Color format error Use valid hex color codes
400 Invalid font_size value Font size is out of range Font size should be between 8-72
400 Invalid font_weight value Font weight error Use preset font weight values
400 Invalid apply_to value Application scope error Use preset application scope values
404 Draft does not exist Specified draft cannot be found Confirm the draft URL is correct and exists
404 Text element does not exist Specified text element cannot be found Confirm the element_id is correct and exists
500 Text style creation failed Internal service error Contact technical support or try again later
503 Service unavailable System under maintenance Try again later

Notes

  1. Element ID: Make sure the element_id exists and is unique, used to identify the target text element
  2. Color Format: Use valid hex color codes (e.g., #FF6B35)
  3. Font Size: Adjust font size appropriately to ensure text readability
  4. Application Scope: Choose appropriate application scope to achieve precise style control
  5. Keyword Matching: Keyword matching is case-sensitive, ensure accurate matching
  6. Style Priority: When multiple styles conflict, the later created styles take precedence
  7. Performance Optimization: Avoid creating too many text styles to prevent performance issues
  8. Compatibility: Test style effects on different devices to ensure good compatibility
  9. Network Stability: Creating text styles requires network support, ensure stable network connection

Workflow

  1. Verify draft_url and text_styles parameters
  2. Validate element_id and text element existence
  3. Parse style configuration parameters
  4. Apply keyword matching rules
  5. Generate rich text style objects
  6. Apply styles to the corresponding text elements
  7. Update draft configuration file
  8. Return updated draft information

Next Steps

After creating text styles, you can continue to use the following interfaces to improve the video:

  • add_videos: Add video materials
  • add_images: Add image materials
  • add_audios: Add audio materials
  • add_captions: Add subtitles
  • add_effects: Add special effects
  • save_draft: Save draft
  • gen_video: Export video

Related Interfaces


πŸ“š Project Resources

GitHub: https://github.com/Hommy-master/capcut-mate

Gitee: https://gitee.com/taohongmin-gitee/capcut-mate

Top comments (0)