monitor-openapi

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
yaml
openapi: 3.1.0
info:
  title: Parallel Monitor API
  version: 1.0.0-alpha
  description: |
    # Monitor API

    The Monitor API lets you continuously track the web for changes relevant to a query, on a schedule you control. Create a monitor with a natural-language query, choose a cadence (hourly, daily, weekly), and receive webhook notifications.

    **Alpha Notice**: The Monitor API is currently in public alpha. Endpoints and request/response formats are subject to change.

    ## Features and Use Cases

    - **News tracking**: Alert when there's notable news about a company or product
    - **Competitive monitoring**: Detect when competitors launch new features or pricing changes
    - **Regulatory updates**: Track new rules or guidance impacting your industry
    - **Deal/research watchlists**: Surface events about entities you care about
    - **Product tracking**: Track modifications to product listings

    ## Supported Features

    - **Scheduling**: Set update cadence to Hourly, Daily, or Weekly
    - **Webhooks**: Receive updates when events are detected or when monitors finish a scheduled run
    - **Events history**: Retrieve updates from recent runs or via a lookback window (e.g., `10d`)
    - **Lifecycle management**: Update cadence, webhook, or metadata; delete to stop future runs
    - **Structured outputs**: Define JSON schemas for consistent, machine-readable event data

    ## Best Practices

    ### Event Tracking
    Use Monitor to track when something happens on the web:

    | Use Case | Example Query |
    |----------|---------------|
    | Brand mentions | "Let me know when someone mentions Parallel Web Systems on the web" |
    | News tracking | "What is the latest AI funding news?" |
    | Product announcements | "Alert me when Apple announces new MacBook models" |
    | Regulatory updates | "Notify me of any new FDA guidance on AI in medical devices" |

    ### Change Tracking
    Use Monitor to detect when something changes:

    | Use Case | Example Query |
    |----------|---------------|
    | Price monitoring | "Let me know when the price for AirPods drops below $150" |
    | Stock availability | "Alert me when the PS5 Pro is back in stock at Best Buy" |
    | Content updates | "Notify me when the React documentation is updated" |
    | Policy changes | "Track changes to OpenAI's terms of service" |

    ### Writing Effective Queries

    Monitor works best with natural language queries that clearly describe what you're looking for.

    **Good practices:**
    - ✅ Use natural language that describes intent: "Parallel Web Systems (parallel.ai) launch or funding updates"
    - ✅ Focus on what you want to track: "AI startup funding announcements"
    - ✅ Be specific about the topic: "Tesla news and announcements"

    **Avoid:**
    - ❌ Keyword-heavy queries: "Parallel OR Parallel Web Systems OR Parallel AI AND Funding OR Launch"
    - ❌ Historical research queries: "Find all AI funding news from the last 2 years" (use Deep Research API instead)
    - ❌ Including specific dates: "Tesla news after December 12, 2025" (Monitor tracks from creation automatically)

    ## Events and Event Groups

    Monitors produce a stream of events each time they run. These events capture:
    - New results detected by your query (events)
    - Run completions
    - Errors (if a run fails)

    Related events are grouped by an `event_group_id` so you can fetch the full set of results that belong to the same discovery.

    ### Event Groups
    Event groups collect related results under a single `event_group_id`. When a monitor detects new results, it creates an event group. Subsequent runs can add additional events to the same group if they're related to the same discovery.

    Use event groups to present the full context of a discovery (multiple sources, follow-up updates) as one unit. To fetch the complete set of results for a discovery, use the GET event group endpoint with the `event_group_id` received in your webhook payload.

    ### Other Events
    Besides events with new results, monitors emit:
    - **Completion** (`type: "completion"`): indicates a run finished successfully
    - **Error** (`type: "error"`): indicates a run failed

    **Note**: Runs with non-empty events are not included in completions. This means that a run will correspond to only one of successful event detection, completion or failure.

    ## Accessing Events

    You can receive events via webhooks (recommended) or retrieve them via endpoints.

    - **Webhooks (recommended)**: lowest latency, push-based delivery. Subscribe to `monitor.event.detected`, `monitor.execution.completed`, and `monitor.execution.failed`.
    - **Endpoints (for history/backfill)**:
      - List monitor events — list events for a monitor in reverse chronological order (up to recent ~300 runs). This flattens out events, meaning that multiple events from the same event group will be listed as different events.
      - Retrieve event group — list all events given an `event_group_id`.

    ## Webhooks

    Webhooks allow you to receive real-time notifications when a Monitor execution completes, fails, or when material events are detected, eliminating the need for polling.

    ### Setup
    Include a `webhook` parameter when creating the monitor with:
    - `url`: Your webhook endpoint URL (can be any domain you control)
    - `event_types`: Array of event types to subscribe to

    ### Event Types
    - `monitor.event.detected`: Emitted when a run detects one or more material events
    - `monitor.execution.completed`: Emitted when a Monitor run completes successfully (without detected events)
    - `monitor.execution.failed`: Emitted when a Monitor run fails due to an error

    **Note**: `monitor.event.detected` and `monitor.execution.completed` are mutually distinct and correspond to different runs.

    ### Webhook Payload Structure

    The `data` object contains:
    - `monitor_id`: The unique ID of the Monitor
    - `event`: The event record for this run
    - `metadata`: User-provided metadata from the Monitor (if any)

    ### Security & Verification

    **Prerequisites**: Before implementing Monitor webhooks, refer to the Webhook Setup & Verification guide for:
    - Recording your webhook secret
    - Verifying HMAC signatures
    - Security best practices
    - Retry policies

    ## Structured Outputs

    Structured outputs enable you to define a JSON schema for monitor events. Each detected event conforms to the specified schema, returning data in a consistent, machine-readable format suitable for downstream processing.

    **Schema Complexity**: Output schemas are currently limited to the complexity supported by the core processor. Use flat schemas with a small number of clearly defined fields.

    ### Best Practices for Schemas
    - Include property descriptions for each property to improve extraction accuracy
    - Use primitive types (limit to `string` and `enum` for reliable parsing)
    - Maintain flat schemas (3-5 properties with single-level object structure)
    - Define edge case handling (specify how missing or inapplicable values should be represented)

    ## Slack Integration

    The Parallel Slack app brings Monitor directly into your Slack workspace. Create monitors with slash commands and receive updates in dedicated threads.

    ### Installation
    1. Go to platform.parallel.ai and navigate to the Integrations section
    2. Click **Add to Slack** to begin the OAuth flow
    3. Authorize the Parallel app in your workspace
    4. Invite the bot to any channel: `/invite @Parallel`

    ### Commands
    - `/monitor <query>` - Create a daily monitor
    - `/hourly <query>` - Create an hourly monitor
    - `/help` - View available commands
    - Reply with `cancelmonitor` in a monitoring thread to cancel

    ## Rate Limits

    See the Rate Limits documentation for default quotas and how to request higher limits.

    ## Pricing

    See the Pricing documentation for a detailed schedule of rates.
  contact:
    name: Parallel Support
    url: https://parallel.ai
    email: support@parallel.ai

servers:
  - url: https://api.parallel.ai
    description: Parallel API

security:
  - ApiKeyAuth: []

tags:
  - name: Monitors
    description: Monitor lifecycle operations (create, retrieve, update, delete)
  - name: Events
    description: Event retrieval and event group operations
  - name: Testing
    description: Webhook testing and simulation

paths:
  /v1alpha/monitors:
    post:
      tags:
        - Monitors
      summary: Create Monitor
      operationId: create_monitor
      description: |
        Creates a monitor that periodically runs the specified query over the web at the specified cadence (hourly, daily, or weekly). The monitor runs once at creation and then continues according to the specified frequency.

        Updates will be sent to the webhook if provided. Use the events endpoints to retrieve execution history for a monitor.

        ## Lifecycle

        The Monitor API follows a straightforward lifecycle:
        1. **Create**: Define your `query`, `cadence`, and optional `webhook` and `metadata`
        2. **Update**: Change cadence, webhook, or metadata
        3. **Delete**: Delete a monitor and stop future executions

        ## Best Practices

        1. **Scope your query**: Clear queries with explicit instructions lead to higher-quality event detection
        2. **Choose the right cadence**: Use `hourly` for fast-moving topics, `daily` for most news, `weekly` for slower changes
        3. **Use webhooks**: Prefer webhooks to avoid unnecessary polling and reduce latency to updates
        4. **Manage lifecycle**: Cancel monitors you no longer need to reduce your usage bills
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateMonitorRequest"
            examples:
              basic:
                summary: Basic daily monitor
                value:
                  query: "Extract recent news about AI"
                  cadence: "daily"
              with_webhook:
                summary: Monitor with webhook
                value:
                  query: "Extract recent news about quantum in AI"
                  cadence: "daily"
                  webhook:
                    url: "https://example.com/webhook"
                    event_types: ["monitor.event.detected"]
                  metadata:
                    key: "value"
              structured_output:
                summary: Monitor with structured output
                value:
                  query: "monitor ai news"
                  cadence: "daily"
                  output_schema:
                    type: "json"
                    json_schema:
                      type: "object"
                      properties:
                        company_name:
                          type: "string"
                          description: "Name of the company the news is about, NA if not company-specific"
                        sentiment:
                          type: "string"
                          description: "Sentiment of the news: positive or negative"
                        description:
                          type: "string"
                          description: "Brief description of the news"
      responses:
        "201":
          description: Monitor created successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
              example:
                monitor_id: "monitor_b0079f70195e4258a3b982c1b6d8bd3a"
                query: "Extract recent news about AI"
                status: "active"
                cadence: "daily"
                metadata:
                  key: "value"
                webhook:
                  url: "https://example.com/webhook"
                  event_types:
                    - "monitor.event.detected"
                created_at: "2025-04-23T20:21:48.037943Z"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "422":
          $ref: "#/components/responses/ValidationError"

    get:
      tags:
        - Monitors
      summary: List Monitors
      operationId: list_monitors
      description: |
        Retrieves a list of all monitors for the authenticated user.

        Returns monitors in reverse chronological order (most recently created first).
      responses:
        "200":
          description: List of monitors
          content:
            application/json:
              schema:
                type: object
                properties:
                  monitors:
                    type: array
                    items:
                      $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"

  /v1alpha/monitors/{monitor_id}:
    get:
      tags:
        - Monitors
      summary: Retrieve Monitor
      operationId: get_monitor
      description: |
        Retrieves details of a specific monitor by ID.

        Returns the monitor's current configuration, status, and metadata.
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      responses:
        "200":
          description: Monitor details
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

    patch:
      tags:
        - Monitors
      summary: Update Monitor
      operationId: update_monitor
      description: |
        Updates a monitor's configuration.

        You can update:
        - `cadence`: Change the monitoring frequency
        - `webhook`: Update webhook URL or event types
        - `metadata`: Update user-provided metadata

        The query cannot be updated after creation. To change the query, create a new monitor.
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateMonitorRequest"
            examples:
              update_cadence:
                summary: Update cadence
                value:
                  cadence: "weekly"
              update_webhook:
                summary: Update webhook
                value:
                  webhook:
                    url: "https://new-endpoint.com/webhook"
                    event_types:
                      ["monitor.event.detected", "monitor.execution.failed"]
              update_metadata:
                summary: Update metadata
                value:
                  metadata:
                    team: "product"
                    priority: "high"
      responses:
        "200":
          description: Monitor updated successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"
        "422":
          $ref: "#/components/responses/ValidationError"

    delete:
      tags:
        - Monitors
      summary: Delete Monitor
      operationId: delete_monitor
      description: |
        Deletes a monitor, stopping all future executions.

        Deleted monitors can no longer be updated or retrieved. This action is irreversible.

        Use this to clean up monitors you no longer need and reduce usage.
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      responses:
        "200":
          description: Monitor deleted successfully
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

  /v1alpha/monitors/{monitor_id}/events:
    get:
      tags:
        - Events
      summary: List Events
      operationId: list_monitor_events
      description: |
        Lists events for a monitor from up to the last 300 event groups.

        Retrieves events from the monitor, including events with errors and material changes. The endpoint checks up to the specified lookback period or the previous 300 event groups, whichever is less.

        Events will be returned in reverse chronological order, with the most recent event groups first. All events from an event group will be flattened out into individual entries in the list.

        ## Event Types Returned

        - **Event** (`type: "event"`): Material change or discovery detected by the monitor
        - **Completion** (`type: "completion"`): Monitor run completed successfully without detected events
        - **Error** (`type: "error"`): Monitor run failed

        ## Structured Output Events

        When a monitor is configured with an output schema, events include a `result` field containing the parsed JSON object conforming to the schema.
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: lookback_period
          in: query
          required: false
          schema:
            type: string
            default: "10d"
            pattern: '^\d+[dw]$'
          description: |
            Lookback period to fetch events from. Sample values: `10d`, `1w`.

            - A minimum of 1 day is supported with one day increments
            - Use `d` for days, `w` for weeks
            - Examples: `7d` (7 days), `2w` (2 weeks)
      responses:
        "200":
          description: List of monitor events
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorEventList"
              examples:
                mixed_events:
                  summary: Mixed event types
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
                        output: "New product launch announced"
                        event_date: "2025-01-15"
                        source_urls:
                          - "https://example.com/news"
                        result:
                          type: "text"
                          content: "New product launch announced"
                      - type: "completion"
                        monitor_ts: "completed_2025-01-15T10:30:00Z"
                      - type: "error"
                        error: "Error occurred while processing the event"
                        id: "error_2025-01-15T10:30:00Z"
                        date: "2025-01-15T10:30:00Z"
                structured_output:
                  summary: Events with structured output
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_f9727e22dd4a42ba5e7fdcaa36b2b8ea2ef7c11f15fb4061"
                        output: ""
                        event_date: "2025-12-02"
                        source_urls:
                          - "https://www.cnbc.com/2025/12/02/youtube-ai-biometric-data-creator-deepfake.html"
                        result:
                          type: "json"
                          content:
                            company_name: "YouTube/Google"
                            sentiment: "negative"
                            description: "YouTube expanded a likeness detection deepfake tracking tool"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"
        "422":
          $ref: "#/components/responses/ValidationError"

  /v1alpha/monitors/{monitor_id}/event_groups/{event_group_id}:
    get:
      tags:
        - Events
      summary: Retrieve Event Group
      operationId: get_event_group
      description: |
        Retrieves all events within a specific event group.

        Event groups collect related results under a single `event_group_id`. Use this endpoint to fetch the complete set of results for a discovery when you receive an `event_group_id` in a webhook payload.

        ## Use with Webhooks

        When a webhook fires with a `monitor.event.detected` event, it returns an `event_group_id`. Use this endpoint to retrieve the full context of the discovery.

        ## Test Event Groups

        When you simulate a `monitor.event.detected` event, the webhook payload includes a test `event_group_id`. You can retrieve this test event group using this endpoint to verify your full webhook processing pipeline.
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: event_group_id
          in: path
          required: true
          schema:
            type: string
          description: The event group ID to retrieve
      responses:
        "200":
          description: Event group details
          content:
            application/json:
              schema:
                type: object
                properties:
                  events:
                    type: array
                    items:
                      $ref: "#/components/schemas/MonitorEventDetail"
              examples:
                text_result:
                  summary: Text output event group
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
                        output: "New product launch announced"
                        event_date: "2025-01-15"
                        source_urls:
                          - "https://example.com/news"
                        result:
                          type: "text"
                          content: "New product launch announced"
                json_result:
                  summary: Structured output event group
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_f9727e22dd4a42ba5e7fdcaa36b2b8ea2ef7c11f15fb4061"
                        output: ""
                        event_date: "2025-12-02"
                        source_urls:
                          - "https://www.cnbc.com/2025/12/02/youtube-ai-biometric-data-creator-deepfake.html"
                        result:
                          type: "json"
                          content:
                            company_name: "YouTube/Google"
                            sentiment: "negative"
                            description: "YouTube expanded a likeness detection deepfake tracking tool"
                test_event_group:
                  summary: Test event group (no structured output)
                  value:
                    events:
                      - type: "event"
                        event_group_id: "test_abc"
                        output: ""
                        event_date: "2025-12-05"
                        source_urls:
                          - "https://test.example.com"
                        result:
                          type: "text"
                          content: "This is a test event."
                test_event_group_structured:
                  summary: Test event group (with structured output)
                  value:
                    events:
                      - type: "event"
                        event_group_id: "test_def"
                        output: ""
                        event_date: "2025-12-05"
                        source_urls:
                          - "https://test.example.com"
                        result:
                          type: "json"
                          content:
                            sentiment: ""
                            stock_ticker_symbol: ""
                            description: ""
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"

  /v1alpha/monitors/{monitor_id}/simulate_event:
    post:
      tags:
        - Testing
      summary: Simulate Event
      operationId: simulate_event
      description: |
        Tests your webhook integration by simulating monitor events.

        The simulate event endpoint allows you to test your webhook integration without waiting for a scheduled monitor run.

        ## Test Event Groups

        When you simulate a `monitor.event.detected` event, the webhook payload includes a test `event_group_id`. You can retrieve this test event group using the standard retrieve event group endpoint.

        Test event group IDs return dummy event data, allowing you to verify your full webhook processing pipeline—from receiving the webhook to fetching event details.

        ## Prerequisites

        - The monitor must have a webhook configured
        - The webhook URL must be accessible
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: event_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - monitor.event.detected
              - monitor.execution.completed
              - monitor.execution.failed
            default: monitor.event.detected
          description: Event type to simulate
      responses:
        "204":
          description: Event simulated successfully (webhook notification sent)
        "400":
          description: Webhook not configured for this monitor
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                type: "error"
                error:
                  ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
                  message: "Webhook not configured for this monitor"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: |
        API key for authentication. Generate your API key on the Parallel Platform.

        Set your API key in the `x-api-key` header for all requests.

  parameters:
    MonitorId:
      name: monitor_id
      in: path
      required: true
      schema:
        type: string
      description: The unique identifier for the monitor

  responses:
    Unauthorized:
      description: "Unauthorized: invalid or missing credentials"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "Unauthorized: invalid or missing credentials"

    ValidationError:
      description: "Unprocessable content: request validation error"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "Unprocessable content: request validation error"

    MonitorNotFound:
      description: Monitor not found
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "Monitor not found"

    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "Resource not found"

  schemas:
    CreateMonitorRequest:
      type: object
      required:
        - query
        - cadence
      properties:
        query:
          type: string
          description: |
            Search query to monitor for material changes.

            Write queries in natural language that clearly describe what you're looking for. The query should focus on intent rather than keywords.
          examples:
            - "Extract recent news about AI"
            - "Let me know when someone mentions Parallel Web Systems on the web"
            - "Alert me when the price for AirPods drops below $150"
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: |
            Cadence of the monitor.

            - `hourly`: For fast-moving topics
            - `daily`: For most news and updates
            - `weekly`: For slower changes
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: |
            User-provided metadata stored with the monitor.

            This field is returned in webhook notifications and GET requests, enabling you to map responses to corresponding objects in your application.

            For example, if you are building a Slackbot that monitors changes, you could store the Slack thread ID here to properly route webhook responses back to the correct conversation thread.
          example:
            slack_thread_id: "1234567890.123456"
            user_id: "U123ABC"
        output_schema:
          $ref: "#/components/schemas/JsonSchema"

    UpdateMonitorRequest:
      type: object
      properties:
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: Updated cadence for the monitor
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: Updated user-provided metadata

    MonitorResponse:
      type: object
      required:
        - monitor_id
        - query
        - status
        - cadence
        - created_at
      properties:
        monitor_id:
          type: string
          description: Unique identifier for the monitor
        query:
          type: string
          description: The query being monitored
          example: "Recent news about LLM models."
        status:
          type: string
          enum:
            - active
            - canceled
          description: Current status of the monitor
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: Frequency of monitor runs
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: User-provided metadata stored with the monitor
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        created_at:
          type: string
          format: date-time
          description: Timestamp when the monitor was created
          example: "2025-01-15T10:30:00Z"
        last_run_at:
          type: string
          format: date-time
          nullable: true
          description: Timestamp of the last monitor run
          example: "2025-01-15T10:30:00Z"

    MonitorWebhook:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
          description: |
            URL for the webhook endpoint.

            This can be any domain you control. The endpoint will receive POST requests with event payloads.
          example: "https://example.com/webhook"
        event_types:
          type: array
          items:
            type: string
            enum:
              - monitor.event.detected
              - monitor.execution.completed
              - monitor.execution.failed
          description: |
            Event types to send webhook notifications for.

            - `monitor.event.detected`: Emitted when a run detects one or more material events
            - `monitor.execution.completed`: Emitted when a Monitor run completes successfully (without detected events)
            - `monitor.execution.failed`: Emitted when a Monitor run fails due to an error

            Note: `monitor.event.detected` and `monitor.execution.completed` are mutually distinct and correspond to different runs.
      description: |
        Webhook configuration for a monitor.

        ## Webhook Payload Structure

        For `monitor.event.detected`:
        ```json
        {
          "type": "monitor.event.detected",
          "timestamp": "2025-10-27T14:56:05.619331Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "event_group_id": "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

        For `monitor.execution.completed`:
        ```json
        {
          "type": "monitor.execution.completed",
          "timestamp": "2025-10-27T14:56:05.619331Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "type": "completion",
              "monitor_ts": "completed_2025-01-15T10:30:00Z"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

        For `monitor.execution.failed`:
        ```json
        {
          "type": "monitor.execution.failed",
          "timestamp": "2025-10-27T14:57:30.789012Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "type": "error",
              "error": "Error occurred while processing the event",
              "id": "error_2025-01-15T10:30:00Z",
              "date": "2025-01-15T10:30:00Z"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

    JsonSchema:
      type: object
      required:
        - json_schema
      properties:
        type:
          type: string
          const: json
          default: json
          description: The type of schema being defined. Always `json`.
        json_schema:
          type: object
          additionalProperties: true
          description: |
            A JSON Schema object. Only a subset of JSON Schema is supported.

            ## Best Practices

            - Include property descriptions for each property to improve extraction accuracy
            - Use primitive types (limit to `string` and `enum` for reliable parsing)
            - Maintain flat schemas (3-5 properties with single-level object structure)
            - Define edge case handling (specify how missing or inapplicable values should be represented)

            ## Schema Complexity

            Output schemas are currently limited to the complexity supported by the core processor. Use flat schemas with a small number of clearly defined fields.
          example:
            type: "object"
            properties:
              gdp:
                type: "string"
                description: "GDP in USD for the year, formatted like '$3.1 trillion (2023)'"
            required:
              - gdp
            additionalProperties: false

    MonitorEventList:
      type: object
      required:
        - events
      properties:
        events:
          type: array
          description: List of execution events for the monitor
          items:
            oneOf:
              - $ref: "#/components/schemas/MonitorEventDetail"
              - $ref: "#/components/schemas/MonitorCompletion"
              - $ref: "#/components/schemas/MonitorExecutionError"
            discriminator:
              propertyName: type
              mapping:
                event: "#/components/schemas/MonitorEventDetail"
                completion: "#/components/schemas/MonitorCompletion"
                error: "#/components/schemas/MonitorExecutionError"

    MonitorEventDetail:
      type: object
      required:
        - type
        - event_group_id
        - output
        - source_urls
        - result
      properties:
        type:
          type: string
          enum:
            - event
          const: event
          default: event
          description: Type of the event
        event_group_id:
          type: string
          description: |
            Event group ID.

            Related events share the same event_group_id. Use this with the retrieve event group endpoint to fetch all events in the group.
        output:
          type: string
          deprecated: true
          description: "Detected change or event. Deprecated: use 'result' field instead."
        event_date:
          type: string
          format: date
          nullable: true
          description: Date when event occurred
          example: "2025-01-15"
        source_urls:
          type: array
          items:
            type: string
            format: uri
          description: List of source URLs supporting the event
          example:
            - "https://example.com/news"
        result:
          oneOf:
            - $ref: "#/components/schemas/MonitorEventTextResult"
            - $ref: "#/components/schemas/MonitorEventJsonResult"
          discriminator:
            propertyName: type
            mapping:
              text: "#/components/schemas/MonitorEventTextResult"
              json: "#/components/schemas/MonitorEventJsonResult"
          description: |
            Output from the event. Either Text or JSON output.

            For monitors without an output schema, this will be a text result. For monitors with an output schema, this will be a JSON result conforming to the schema.

    MonitorEventTextResult:
      type: object
      required:
        - type
        - content
      properties:
        type:
          type: string
          enum:
            - text
          const: text
          default: text
          description: Type of the result
        content:
          type: string
          description: Text content of the result

    MonitorEventJsonResult:
      type: object
      required:
        - type
        - content
      properties:
        type:
          type: string
          enum:
            - json
          const: json
          default: json
          description: Type of the result
        content:
          type: object
          additionalProperties: true
          description: |
            JSON content of the result.

            This object conforms to the output schema defined when creating the monitor.

    MonitorCompletion:
      type: object
      required:
        - type
        - monitor_ts
      properties:
        type:
          type: string
          enum:
            - completion
          const: completion
          default: completion
          description: Type of the event
        monitor_ts:
          type: string
          description: Identifier for the completed event
          example: "completed_2025-01-15T10:30:00Z"

    MonitorExecutionError:
      type: object
      required:
        - type
        - error
        - id
        - date
      properties:
        type:
          type: string
          enum:
            - error
          const: error
          default: error
          description: Type of the event
        error:
          type: string
          description: Human-readable error message
        id:
          type: string
          description: Identifier for the error event
        date:
          type: string
          format: date-time
          description: Timestamp when the error occurred

    ErrorResponse:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          const: error
          description: Always 'error'
        error:
          $ref: "#/components/schemas/Error"

    Error:
      type: object
      required:
        - ref_id
        - message
      properties:
        ref_id:
          type: string
          description: Reference ID for the error
        message:
          type: string
          description: Human-readable error message
        detail:
          type: object
          additionalProperties: true
          nullable: true
          description: Optional detail supporting the error
yaml
openapi: 3.1.0
info:
  title: Parallel Monitor API
  version: 1.0.0-alpha
  description: |
    # Monitor API

    Monitor API允许你按照自定义的计划,持续跟踪与指定查询相关的网页变化。你可以通过自然语言查询创建监控任务,选择执行频率(每小时、每天、每周),并接收Webhook通知。

    **Alpha版本说明**:Monitor API目前处于公开测试阶段。接口及请求/响应格式可能会随时调整。

    ## 功能与应用场景

    - **新闻追踪**:当出现与某家公司或产品相关的重要新闻时发出提醒
    - **竞品监控**:检测竞争对手何时推出新功能或调整定价
    - **法规更新**:跟踪影响所在行业的新规则或指导意见
    - **交易/研究关注列表**:展示与你关注的实体相关的事件
    - **产品追踪**:跟踪产品列表的修改情况

    ## 支持的功能

    - **任务调度**:设置每小时、每天或每周的更新频率
    - **Webhook通知**:当检测到事件或监控任务完成时接收通知
    - **事件历史**:获取最近运行的更新或指定回溯周期内的记录(例如`10d`)
    - **生命周期管理**:更新执行频率、Webhook配置或元数据;删除任务以停止后续运行
    - **结构化输出**:定义JSON Schema,使事件数据保持一致的机器可读格式

    ## 最佳实践

    ### 事件追踪
    使用Monitor API跟踪网页上发生的特定事件:

    | 应用场景 | 查询示例 |
    |----------|---------------|
    | 品牌提及 | "当网页上有人提到Parallel Web Systems时通知我" |
    | 新闻追踪 | "获取最新的AI融资新闻" |
    | 产品发布 | "当苹果发布新MacBook型号时提醒我" |
    | 法规更新 | "通知我FDA关于医疗设备AI应用的新指导意见" |

    ### 变化追踪
    使用Monitor API检测网页内容的变化:

    | 应用场景 | 查询示例 |
    |----------|---------------|
    | 价格监控 | "当AirPods价格低于150美元时通知我" |
    | 库存状态 | "当Best Buy的PS5 Pro补货时提醒我" |
    | 内容更新 | "当React文档更新时通知我" |
    | 政策变更 | "跟踪OpenAI服务条款的变化" |

    ### 编写高效查询

    Monitor API在处理清晰描述需求的自然语言查询时效果最佳。

    **推荐做法:**
    - ✅ 使用描述意图的自然语言:"Parallel Web Systems(parallel.ai)的发布或融资更新"
    - ✅ 聚焦追踪目标:"AI初创公司融资公告"
    - ✅ 明确主题:"特斯拉新闻与公告"

    **避免:**
    - ❌ 关键词堆砌的查询:"Parallel OR Parallel Web Systems OR Parallel AI AND Funding OR Launch"
    - ❌ 历史研究类查询:"查找过去2年所有的AI融资新闻"(请使用Deep Research API)
    - ❌ 包含特定日期:"2025年12月12日之后的特斯拉新闻"(Monitor API会自动从创建时开始追踪)

    ## 事件与事件组

    每次监控任务运行时都会生成一系列事件,这些事件包括:
    - 查询检测到的新结果(事件)
    - 任务完成记录
    - 错误信息(如果任务运行失败)

    相关事件会通过`event_group_id`进行分组,你可以获取同一发现对应的完整结果集。

    ### 事件组
    事件组通过单一`event_group_id`聚合相关结果。当监控任务检测到新结果时,会创建一个事件组。后续运行如果发现与同一发现相关的结果,会将其添加到该事件组中。

    使用事件组可以将同一发现的完整上下文(多来源、后续更新)作为一个单元展示。要获取某一发现的完整结果集,可以使用GET事件组接口,传入Webhook payload中的`event_group_id`。

    ### 其他事件类型
    除了包含新结果的事件外,监控任务还会生成:
    - **完成事件**(`type: "completion"`):表示任务成功完成
    - **错误事件**(`type: "error"`):表示任务运行失败

    **注意**:包含非空事件的任务不会触发完成事件。这意味着一次任务运行只会对应成功检测事件、完成事件或失败事件中的一种。

    ## 事件获取方式

    你可以通过Webhook(推荐)或接口两种方式获取事件:

    - **Webhook(推荐)**:延迟最低,采用推送式交付。订阅`monitor.event.detected`、`monitor.execution.completed`和`monitor.execution.failed`事件类型。
    - **接口(用于历史记录/回填)**:
      - 列出监控事件:按时间倒序列出某一监控任务的事件(最多最近300次运行)。该接口会将事件组中的所有事件展平为列表中的单独条目。
      - 获取事件组:传入`event_group_id`获取该组下的所有事件。

    ## Webhook配置

    Webhook允许你在监控任务完成、失败或检测到重要事件时接收实时通知,无需轮询接口。

    ### 设置步骤
    创建监控任务时,包含`webhook`参数,其中:
    - `url`:你的Webhook端点URL(可以是你控制的任何域名)
    - `event_types`:要订阅的事件类型数组

    ### 事件类型
    - `monitor.event.detected`:当任务检测到一个或多个重要事件时触发
    - `monitor.execution.completed`:当监控任务成功完成且未检测到事件时触发
    - `monitor.execution.failed`:当监控任务因错误运行失败时触发

    **注意**:`monitor.event.detected`和`monitor.execution.completed`是互斥的,分别对应不同的任务运行。

    ### Webhook Payload结构

    `data`对象包含:
    - `monitor_id`:监控任务的唯一ID
    - `event`:本次运行的事件记录
    - `metadata`:监控任务的用户自定义元数据(如果有)

    ### 安全与验证

    **前提条件**:在实现Monitor Webhook之前,请参考《Webhook设置与验证指南》了解:
    - 记录Webhook密钥
    - 验证HMAC签名
    - 安全最佳实践
    - 重试策略

    ## 结构化输出

    结构化输出允许你为监控事件定义JSON Schema。每个检测到的事件都会符合指定的Schema,返回一致的机器可读格式数据,便于下游处理。

    **Schema复杂度限制**:当前输出Schema的复杂度受核心处理器支持范围限制。建议使用包含少量明确定义字段的扁平Schema。

    ### Schema最佳实践
    - 为每个属性添加描述,提高提取准确性
    - 使用基本数据类型(建议仅使用`string`和`enum`以确保可靠解析)
    - 保持Schema扁平(3-5个属性,单层对象结构)
    - 定义边缘情况处理规则(指定缺失或不适用值的表示方式)

    ## Slack集成

    Parallel Slack应用可将Monitor功能直接集成到你的Slack工作区。通过斜杠命令创建监控任务,并在专用线程中接收更新。

    ### 安装步骤
    1. 访问platform.parallel.ai并导航到集成页面
    2. 点击**Add to Slack**开始OAuth流程
    3. 在工作区中授权Parallel应用
    4. 在任意频道中邀请机器人:`/invite @Parallel`

    ### 可用命令
    - `/monitor <query>` - 创建每日监控任务
    - `/hourly <query>` - 创建每小时监控任务
    - `/help` - 查看所有可用命令
    - 在监控线程中回复`cancelmonitor`以取消任务

    ## 速率限制

    请参考《速率限制文档》了解默认配额及申请更高限额的方式。

    ## 定价

    请参考《定价文档》了解详细的费率说明。
  contact:
    name: Parallel Support
    url: https://parallel.ai
    email: support@parallel.ai

servers:
  - url: https://api.parallel.ai
    description: Parallel API服务器

security:
  - ApiKeyAuth: []

tags:
  - name: Monitors
    description: 监控任务生命周期操作(创建、查询、更新、删除)
  - name: Events
    description: 事件查询与事件组操作
  - name: Testing
    description: Webhook测试与模拟

paths:
  /v1alpha/monitors:
    post:
      tags:
        - Monitors
      summary: 创建监控任务
      operationId: create_monitor
      description: |
        创建一个监控任务,按照指定频率(每小时、每天、每周)定期在网页上运行指定查询。任务会在创建时立即运行一次,之后按照指定频率持续执行。

        如果配置了Webhook,更新会发送到该端点。可通过事件接口获取监控任务的执行历史。

        ## 生命周期

        Monitor API遵循简单的生命周期:
        1. **创建**:定义`query`、`cadence`,可选配置`webhook`和`metadata`
        2. **更新**:修改执行频率、Webhook配置或元数据
        3. **删除**:删除监控任务并停止后续执行

        ## 最佳实践

        1. **明确查询范围**:清晰且指令明确的查询能提高事件检测质量
        2. **选择合适的频率**:快速变化的主题使用`hourly`,多数新闻类主题使用`daily`,慢速变化的主题使用`weekly`
        3. **优先使用Webhook**:通过Webhook避免不必要的轮询,降低更新延迟
        4. **管理任务生命周期**:取消不再需要的任务以减少使用成本
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/CreateMonitorRequest"
            examples:
              basic:
                summary: 基础每日监控任务
                value:
                  query: "提取近期AI相关新闻"
                  cadence: "daily"
              with_webhook:
                summary: 带Webhook的监控任务
                value:
                  query: "提取近期AI领域量子技术相关新闻"
                  cadence: "daily"
                  webhook:
                    url: "https://example.com/webhook"
                    event_types: ["monitor.event.detected"]
                  metadata:
                    key: "value"
              structured_output:
                summary: 带结构化输出的监控任务
                value:
                  query: "监控AI新闻"
                  cadence: "daily"
                  output_schema:
                    type: "json"
                    json_schema:
                      type: "object"
                      properties:
                        company_name:
                          type: "string"
                          description: "新闻涉及的公司名称,如非公司相关则为NA"
                        sentiment:
                          type: "string"
                          description: "新闻情感倾向:正面或负面"
                        description:
                          type: "string"
                          description: "新闻简要描述"
      responses:
        "201":
          description: 监控任务创建成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
              example:
                monitor_id: "monitor_b0079f70195e4258a3b982c1b6d8bd3a"
                query: "提取近期AI相关新闻"
                status: "active"
                cadence: "daily"
                metadata:
                  key: "value"
                webhook:
                  url: "https://example.com/webhook"
                  event_types:
                    - "monitor.event.detected"
                created_at: "2025-04-23T20:21:48.037943Z"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "422":
          $ref: "#/components/responses/ValidationError"

    get:
      tags:
        - Monitors
      summary: 列出所有监控任务
      operationId: list_monitors
      description: |
        获取当前认证用户的所有监控任务列表。

        结果按创建时间倒序排列(最新创建的任务优先)。
      responses:
        "200":
          description: 监控任务列表
          content:
            application/json:
              schema:
                type: object
                properties:
                  monitors:
                    type: array
                    items:
                      $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"

  /v1alpha/monitors/{monitor_id}:
    get:
      tags:
        - Monitors
      summary: 获取单个监控任务详情
      operationId: get_monitor
      description: |
        通过ID获取指定监控任务的详细信息。

        返回监控任务的当前配置、状态和元数据。
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      responses:
        "200":
          description: 监控任务详情
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

    patch:
      tags:
        - Monitors
      summary: 更新监控任务
      operationId: update_monitor
      description: |
        更新监控任务的配置。

        你可以更新以下内容:
        - `cadence`: 修改监控频率
        - `webhook`: 更新Webhook URL或事件类型
        - `metadata`: 更新用户自定义元数据

        查询内容创建后无法修改。如需更改查询,请创建新的监控任务。
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/UpdateMonitorRequest"
            examples:
              update_cadence:
                summary: 更新执行频率
                value:
                  cadence: "weekly"
              update_webhook:
                summary: 更新Webhook配置
                value:
                  webhook:
                    url: "https://new-endpoint.com/webhook"
                    event_types:
                      ["monitor.event.detected", "monitor.execution.failed"]
              update_metadata:
                summary: 更新元数据
                value:
                  metadata:
                    team: "product"
                    priority: "high"
      responses:
        "200":
          description: 监控任务更新成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"
        "422":
          $ref: "#/components/responses/ValidationError"

    delete:
      tags:
        - Monitors
      summary: 删除监控任务
      operationId: delete_monitor
      description: |
        删除监控任务,停止所有后续执行。

        删除后的任务无法再更新或查询。此操作不可逆。

        请使用此功能清理不再需要的任务,降低使用成本。
      parameters:
        - $ref: "#/components/parameters/MonitorId"
      responses:
        "200":
          description: 监控任务删除成功
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorResponse"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

  /v1alpha/monitors/{monitor_id}/events:
    get:
      tags:
        - Events
      summary: 列出监控事件
      operationId: list_monitor_events
      description: |
        列出指定监控任务的最近300个事件组对应的事件。

        获取监控任务的所有事件,包括错误事件和重要变化事件。接口会检查指定回溯周期或最近300个事件组(取范围较小的一个)。

        事件按时间倒序返回,最新的事件组优先。事件组中的所有事件会被展平为列表中的单独条目。

        ## 返回的事件类型

        - **事件**(`type: "event"`):监控任务检测到的重要变化或发现
        - **完成事件**(`type: "completion"`):监控任务成功完成且未检测到事件
        - **错误事件**(`type: "error"`):监控任务运行失败

        ## 结构化输出事件

        当监控任务配置了输出Schema时,事件会包含`result`字段,其中包含符合Schema的解析后JSON对象。
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: lookback_period
          in: query
          required: false
          schema:
            type: string
            default: "10d"
            pattern: '^\d+[dw]$'
          description: |
            用于获取事件的回溯周期。示例值:`10d`、`1w`。

            - 最小支持1天,以1天为增量
            - 使用`d`表示天,`w`表示周
            - 示例:`7d`(7天)、`2w`(2周)
      responses:
        "200":
          description: 监控事件列表
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/MonitorEventList"
              examples:
                mixed_events:
                  summary: 混合事件类型示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
                        output: "新产品发布公告"
                        event_date: "2025-01-15"
                        source_urls:
                          - "https://example.com/news"
                        result:
                          type: "text"
                          content: "新产品发布公告"
                      - type: "completion"
                        monitor_ts: "completed_2025-01-15T10:30:00Z"
                      - type: "error"
                        error: "处理事件时发生错误"
                        id: "error_2025-01-15T10:30:00Z"
                        date: "2025-01-15T10:30:00Z"
                structured_output:
                  summary: 结构化输出事件示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_f9727e22dd4a42ba5e7fdcaa36b2b8ea2ef7c11f15fb4061"
                        output: ""
                        event_date: "2025-12-02"
                        source_urls:
                          - "https://www.cnbc.com/2025/12/02/youtube-ai-biometric-data-creator-deepfake.html"
                        result:
                          type: "json"
                          content:
                            company_name: "YouTube/Google"
                            sentiment: "negative"
                            description: "YouTube扩展了相似性检测深度伪造追踪工具"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"
        "422":
          $ref: "#/components/responses/ValidationError"

  /v1alpha/monitors/{monitor_id}/event_groups/{event_group_id}:
    get:
      tags:
        - Events
      summary: 获取事件组详情
      operationId: get_event_group
      description: |
        获取指定事件组下的所有事件。

        事件组通过单一`event_group_id`聚合相关结果。当你在Webhook payload中收到`event_group_id`时,可以使用此接口获取该发现的完整上下文。

        ## 与Webhook配合使用

        当Webhook触发`monitor.event.detected`事件时,会返回`event_group_id`。使用此接口获取该发现的完整上下文。

        ## 测试事件组

        当你模拟`monitor.event.detected`事件时,Webhook payload会包含测试用`event_group_id`。你可以使用此接口获取该测试事件组,以验证完整的Webhook处理流程。
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: event_group_id
          in: path
          required: true
          schema:
            type: string
          description: 要获取的事件组ID
      responses:
        "200":
          description: 事件组详情
          content:
            application/json:
              schema:
                type: object
                properties:
                  events:
                    type: array
                    items:
                      $ref: "#/components/schemas/MonitorEventDetail"
              examples:
                text_result:
                  summary: 文本输出事件组示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
                        output: "新产品发布公告"
                        event_date: "2025-01-15"
                        source_urls:
                          - "https://example.com/news"
                        result:
                          type: "text"
                          content: "新产品发布公告"
                json_result:
                  summary: 结构化输出事件组示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "mevtgrp_f9727e22dd4a42ba5e7fdcaa36b2b8ea2ef7c11f15fb4061"
                        output: ""
                        event_date: "2025-12-02"
                        source_urls:
                          - "https://www.cnbc.com/2025/12/02/youtube-ai-biometric-data-creator-deepfake.html"
                        result:
                          type: "json"
                          content:
                            company_name: "YouTube/Google"
                            sentiment: "negative"
                            description: "YouTube扩展了相似性检测深度伪造追踪工具"
                test_event_group:
                  summary: 测试事件组(无结构化输出)示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "test_abc"
                        output: ""
                        event_date: "2025-12-05"
                        source_urls:
                          - "https://test.example.com"
                        result:
                          type: "text"
                          content: "这是一个测试事件。"
                test_event_group_structured:
                  summary: 测试事件组(带结构化输出)示例
                  value:
                    events:
                      - type: "event"
                        event_group_id: "test_def"
                        output: ""
                        event_date: "2025-12-05"
                        source_urls:
                          - "https://test.example.com"
                        result:
                          type: "json"
                          content:
                            sentiment: ""
                            stock_ticker_symbol: ""
                            description: ""
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/NotFound"

  /v1alpha/monitors/{monitor_id}/simulate_event:
    post:
      tags:
        - Testing
      summary: 模拟事件
      operationId: simulate_event
      description: |
        通过模拟监控事件测试你的Webhook集成。

        模拟事件接口允许你无需等待监控任务定期运行,即可测试Webhook集成。

        ## 测试事件组

        当你模拟`monitor.event.detected`事件时,Webhook payload会包含测试用`event_group_id`。你可以使用标准的获取事件组接口获取该测试事件组。

        测试事件组ID返回的是模拟事件数据,可用于验证完整的Webhook处理流程——从接收Webhook到获取事件详情。

        ## 前提条件

        - 监控任务必须已配置Webhook
        - Webhook URL必须可访问
      parameters:
        - $ref: "#/components/parameters/MonitorId"
        - name: event_type
          in: query
          required: false
          schema:
            type: string
            enum:
              - monitor.event.detected
              - monitor.execution.completed
              - monitor.execution.failed
            default: monitor.event.detected
          description: 要模拟的事件类型
      responses:
        "204":
          description: 事件模拟成功(已发送Webhook通知)
        "400":
          description: 该监控任务未配置Webhook
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/ErrorResponse"
              example:
                type: "error"
                error:
                  ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
                  message: "该监控任务未配置Webhook"
        "401":
          $ref: "#/components/responses/Unauthorized"
        "404":
          $ref: "#/components/responses/MonitorNotFound"

components:
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: |
        用于身份验证的API密钥。在Parallel平台生成你的API密钥。

        所有请求都需在`x-api-key`头中设置你的API密钥。

  parameters:
    MonitorId:
      name: monitor_id
      in: path
      required: true
      schema:
        type: string
      description: 监控任务的唯一标识符

  responses:
    Unauthorized:
      description: "未授权:凭证无效或缺失"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "未授权:凭证无效或缺失"

    ValidationError:
      description: "无法处理的内容:请求验证错误"
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "无法处理的内容:请求验证错误"

    MonitorNotFound:
      description: 监控任务不存在
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "监控任务不存在"

    NotFound:
      description: 资源不存在
      content:
        application/json:
          schema:
            $ref: "#/components/schemas/ErrorResponse"
          example:
            type: "error"
            error:
              ref_id: "fcb2b4f3-c75e-4186-87bc-caa1a8381331"
              message: "资源不存在"

  schemas:
    CreateMonitorRequest:
      type: object
      required:
        - query
        - cadence
      properties:
        query:
          type: string
          description: |
            用于监控重要变化的搜索查询。

            使用自然语言清晰描述你的需求。查询应聚焦意图而非关键词。
          examples:
            - "提取近期AI相关新闻"
            - "当网页上有人提到Parallel Web Systems时通知我"
            - "当AirPods价格低于150美元时通知我"
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: |
            监控任务的执行频率。

            - `hourly`: 适用于快速变化的主题
            - `daily`: 适用于多数新闻和更新
            - `weekly`: 适用于慢速变化的内容
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: |
            与监控任务关联的用户自定义元数据。

            该字段会在Webhook通知和GET请求中返回,可用于将响应映射到你应用中的对应对象。

            例如,如果你正在构建一个监控变化的Slack机器人,可以在此存储Slack线程ID,以便将Webhook响应正确路由到对应的对话线程。
          example:
            slack_thread_id: "1234567890.123456"
            user_id: "U123ABC"
        output_schema:
          $ref: "#/components/schemas/JsonSchema"

    UpdateMonitorRequest:
      type: object
      properties:
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: 监控任务的更新后执行频率
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: 更新后的用户自定义元数据

    MonitorResponse:
      type: object
      required:
        - monitor_id
        - query
        - status
        - cadence
        - created_at
      properties:
        monitor_id:
          type: string
          description: 监控任务的唯一标识符
        query:
          type: string
          description: 正在监控的查询内容
          example: "近期LLM模型相关新闻。"
        status:
          type: string
          enum:
            - active
            - canceled
          description: 监控任务的当前状态
        cadence:
          type: string
          enum:
            - hourly
            - daily
            - weekly
          description: 监控任务的执行频率
        metadata:
          type: object
          additionalProperties:
            type: string
          nullable: true
          description: 与监控任务关联的用户自定义元数据
        webhook:
          $ref: "#/components/schemas/MonitorWebhook"
        created_at:
          type: string
          format: date-time
          description: 监控任务的创建时间戳
          example: "2025-01-15T10:30:00Z"
        last_run_at:
          type: string
          format: date-time
          nullable: true
          description: 监控任务的最后一次运行时间戳
          example: "2025-01-15T10:30:00Z"

    MonitorWebhook:
      type: object
      required:
        - url
      properties:
        url:
          type: string
          format: uri
          description: |
            Webhook端点的URL。

            可以是你控制的任何域名。该端点会接收包含事件payload的POST请求。
          example: "https://example.com/webhook"
        event_types:
          type: array
          items:
            type: string
            enum:
              - monitor.event.detected
              - monitor.execution.completed
              - monitor.execution.failed
          description: |
            要发送Webhook通知的事件类型。

            - `monitor.event.detected`: 当任务检测到一个或多个重要事件时触发
            - `monitor.execution.completed`: 当监控任务成功完成且未检测到事件时触发
            - `monitor.execution.failed`: 当监控任务因错误运行失败时触发

            注意:`monitor.event.detected`和`monitor.execution.completed`是互斥的,分别对应不同的任务运行。
      description: |
        监控任务的Webhook配置。

        ## Webhook Payload结构

        对于`monitor.event.detected`事件:
        ```json
        {
          "type": "monitor.event.detected",
          "timestamp": "2025-10-27T14:56:05.619331Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "event_group_id": "mevtgrp_b0079f70195e4258eab1e7284340f1a9ec3a8033ed236a24"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

        对于`monitor.execution.completed`事件:
        ```json
        {
          "type": "monitor.execution.completed",
          "timestamp": "2025-10-27T14:56:05.619331Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "type": "completion",
              "monitor_ts": "completed_2025-01-15T10:30:00Z"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

        对于`monitor.execution.failed`事件:
        ```json
        {
          "type": "monitor.execution.failed",
          "timestamp": "2025-10-27T14:57:30.789012Z",
          "data": {
            "monitor_id": "monitor_0c9d7f7d5a7841a0b6c269b2b9b1e6aa",
            "event": {
              "type": "error",
              "error": "处理事件时发生错误",
              "id": "error_2025-01-15T10:30:00Z",
              "date": "2025-01-15T10:30:00Z"
            },
            "metadata": { "team": "research" }
          }
        }
        ```

    JsonSchema:
      type: object
      required:
        - json_schema
      properties:
        type:
          type: string
          const: json
          default: json
          description: 定义的Schema类型,固定为`json`。
        json_schema:
          type: object
          additionalProperties: true
          description: |
            JSON Schema对象。仅支持JSON Schema的子集。

            ## 最佳实践

            - 为每个属性添加描述,提高提取准确性
            - 使用基本数据类型(建议仅使用`string`和`enum`以确保可靠解析)
            - 保持Schema扁平(3-5个属性,单层对象结构)
            - 定义边缘情况处理规则(指定缺失或不适用值的表示方式)

            ## Schema复杂度限制

            当前输出Schema的复杂度受核心处理器支持范围限制。建议使用包含少量明确定义字段的扁平Schema。
          example:
            type: "object"
            properties:
              gdp:
                type: "string"
                description: "年度GDP(美元),格式如'$3.1 trillion (2023)'"
            required:
              - gdp
            additionalProperties: false

    MonitorEventList:
      type: object
      required:
        - events
      properties:
        events:
          type: array
          description: 监控任务的执行事件列表
          items:
            oneOf:
              - $ref: "#/components/schemas/MonitorEventDetail"
              - $ref: "#/components/schemas/MonitorCompletion"
              - $ref: "#/components/schemas/MonitorExecutionError"
            discriminator:
              propertyName: type
              mapping:
                event: "#/components/schemas/MonitorEventDetail"
                completion: "#/components/schemas/MonitorCompletion"
                error: "#/components/schemas/MonitorExecutionError"

    MonitorEventDetail:
      type: object
      required:
        - type
        - event_group_id
        - output
        - source_urls
        - result
      properties:
        type:
          type: string
          enum:
            - event
          const: event
          default: event
          description: 事件类型
        event_group_id:
          type: string
          description: |
            事件组ID。

            相关事件共享同一event_group_id。使用此ID调用获取事件组接口可获取该组下的所有事件。
        output:
          type: string
          deprecated: true
          description: "检测到的变化或事件。已废弃:请使用'result'字段。"
        event_date:
          type: string
          format: date
          nullable: true
          description: 事件发生日期
          example: "2025-01-15"
        source_urls:
          type: array
          items:
            type: string
            format: uri
          description: 支持该事件的来源URL列表
          example:
            - "https://example.com/news"
        result:
          oneOf:
            - $ref: "#/components/schemas/MonitorEventTextResult"
            - $ref: "#/components/schemas/MonitorEventJsonResult"
          discriminator:
            propertyName: type
            mapping:
              text: "#/components/schemas/MonitorEventTextResult"
              json: "#/components/schemas/MonitorEventJsonResult"
          description: |
            事件的输出结果。可以是文本或JSON格式。

            未配置输出Schema的监控任务会返回文本结果,配置了输出Schema的任务会返回符合Schema的JSON结果。

    MonitorEventTextResult:
      type: object
      required:
        - type
        - content
      properties:
        type:
          type: string
          enum:
            - text
          const: text
          default: text
          description: 结果类型
        content:
          type: string
          description: 结果的文本内容

    MonitorEventJsonResult:
      type: object
      required:
        - type
        - content
      properties:
        type:
          type: string
          enum:
            - json
          const: json
          default: json
          description: 结果类型
        content:
          type: object
          additionalProperties: true
          description: |
            结果的JSON内容。

            该对象符合创建监控任务时定义的输出Schema。

    MonitorCompletion:
      type: object
      required:
        - type
        - monitor_ts
      properties:
        type:
          type: string
          enum:
            - completion
          const: completion
          default: completion
          description: 事件类型
        monitor_ts:
          type: string
          description: 完成事件的标识符
          example: "completed_2025-01-15T10:30:00Z"

    MonitorExecutionError:
      type: object
      required:
        - type
        - error
        - id
        - date
      properties:
        type:
          type: string
          enum:
            - error
          const: error
          default: error
          description: 事件类型
        error:
          type: string
          description: 人类可读的错误信息
        id:
          type: string
          description: 错误事件的标识符
        date:
          type: string
          format: date-time
          description: 错误发生的时间戳

    ErrorResponse:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          const: error
          description: 固定为'error'
        error:
          $ref: "#/components/schemas/Error"

    Error:
      type: object
      required:
        - ref_id
        - message
      properties:
        ref_id:
          type: string
          description: 错误的参考ID
        message:
          type: string
          description: 人类可读的错误信息
        detail:
          type: object
          additionalProperties: true
          nullable: true
          description: 支持错误信息的可选详细内容