{
  "openapi": "3.1.0",
  "info": {
    "title": "Text to Audio API",
    "version": "1.0.0",
    "description": "Create a Kling audio-generation task from a text prompt."
  },
  "servers": [
    {
      "url": "https://api.cometapi.com"
    }
  ],
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/kling/v1/audio/text-to-audio": {
      "post": {
        "summary": "Create a Kling text-to-audio task",
        "operationId": "text_to_audio",
        "description": "Submit a text prompt and duration, then poll the returned task id through the generic Kling query route.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "prompt",
                  "duration"
                ],
                "properties": {
                  "prompt": {
                    "type": "string",
                    "description": "Text prompt describing the audio to generate. Max 200 characters."
                  },
                  "duration": {
                    "type": "integer",
                    "description": "Duration of the generated audio in seconds. Range: 3.0–10.0, supports one decimal place."
                  },
                  "external_task_id": {
                    "type": "string",
                    "description": "Optional user-defined task ID for your own tracking. Does not replace the system-generated task ID. Must be unique per account."
                  },
                  "callback_url": {
                    "type": "string",
                    "description": "Webhook URL for task status notifications. The server sends a callback when the task status changes."
                  }
                },
                "default": {
                  "prompt": "Soft ambient ocean waves at sunrise.",
                  "duration": 5
                }
              },
              "examples": {
                "Validated request": {
                  "summary": "Validated request",
                  "value": {
                    "prompt": "Soft ambient ocean waves at sunrise.",
                    "duration": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Task accepted.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "required": [
                    "code",
                    "message",
                    "data"
                  ],
                  "properties": {
                    "code": {
                      "type": "integer",
                      "description": "Error code; specific error code definition\n"
                    },
                    "message": {
                      "type": "string",
                      "description": "Error message\n"
                    },
                    "data": {
                      "type": "object",
                      "required": [
                        "task_id",
                        "task_status",
                        "created_at",
                        "updated_at"
                      ],
                      "properties": {
                        "task_id": {
                          "type": "string",
                          "description": "Task ID, system-generated\n"
                        },
                        "task_status": {
                          "type": "string",
                          "description": "Task status, enum values: submitted, processing, succeed, failed\n"
                        },
                        "created_at": {
                          "type": "integer",
                          "description": "Task creation time, Unix timestamp, in ms\n\n"
                        },
                        "updated_at": {
                          "type": "integer",
                          "description": "Task update time, Unix timestamp, in ms\n"
                        }
                      }
                    }
                  },
                  "example": {
                    "code": 0,
                    "message": "SUCCEED",
                    "data": {
                      "task_id": "861254119619698760",
                      "task_status": "submitted",
                      "task_info": {},
                      "created_at": 1773367502225,
                      "updated_at": 1773367502225
                    }
                  }
                }
              }
            }
          }
        },
        "x-codeSamples": [
          {
            "lang": "Shell",
            "label": "Default",
            "source": "curl https://api.cometapi.com/kling/v1/audio/text-to-audio \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"prompt\": \"Soft ambient ocean waves at sunrise.\",\n      \"duration\": 5\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/kling/v1/audio/text-to-audio\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n            \"prompt\": \"Soft ambient ocean waves at sunrise.\",\n            \"duration\": 5\n    },\n)\n\nresult = response.json()\nprint(result[\"code\"], result.get(\"data\", {}).get(\"task_id\"))  # code 0 means submitted; poll the matching query endpoint until task_status is succeed\n"
          },
          {
            "lang": "JavaScript",
            "label": "Default",
            "source": "const response = await fetch(\"https://api.cometapi.com/kling/v1/audio/text-to-audio\", {\n    method: \"POST\",\n    headers: {\n        Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n        \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\n            \"prompt\": \"Soft ambient ocean waves at sunrise.\",\n            \"duration\": 5\n        }),\n});\n\nconst result = await response.json();\nconsole.log(result.code, result.data?.task_id); // code 0 means submitted; poll the matching query endpoint until task_status is succeed\n"
          }
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  }
}
