# Job

## Create job

POST /v2/team/jobs

Analyze or explore your data. You can use this endpoint to ask questions based on your data and get instant insights.

In MAXIR AI, a **Job** is a Q&A process generated and executed by MAXIR AI based on your request (such as a prompt or other workflow).

> Body Request Parameters

```json
{
  "session_id": "cxxdgegeegeg3433fff",
  "user_id": "tmm-dafasdfasdfasdf",
  "stream": true,
  "question": "Hello World",
  "dataset_id": "cm1gjmg8e0057r3x22v1fdu8m",
  "datasource_ids": [
    "cm1gjmmoo0001h0x24uk1xgu9"
  ],
  "output_language": "AUTO",
  "job_mode": "AUTO"
}
```

### Request Parameters

|Name|Location|Type|Required|Chinese Name|Description|
|---|---|---|---|---|---|
|x-pd-external-trace-id|header|string| No ||Trace ID set in your local system, up to 128 characters. When an error occurs, you can provide this ID to the MAXIR AI team to assist with troubleshooting.|
|body|body|object| No ||none|
|» session_id|body|string| Yes ||Session ID.|
|» stream|body|boolean| No ||Whether to use streaming response. If set to `true`, MAXIR AI will send answer updates to the client in real time, continuously transmitting available data. If set to `false`, the complete response will be returned at once after the answer is finished.|
|» question|body|string| Yes ||Your question (i.e., prompt).|
|» dataset_id|body|string| No ||Dataset ID associated with the job. |
|» datasource_ids|body|[string]| No ||IDs of the data sources to be used in the job. Up to 1,000 data sources can be specified.|
|» output_language|body|string| No ||The reply language of MAXIR AI. For example, when set to `ZH-CN`, MAXIR AI will reply in Simplified Chinese. Optional values include:|
|» job_mode|body|string| No ||Job type. Optional values include:|
|» user_id|body|string| Yes ||User ID, i.e., your unique identifier in the organization.|

#### Detailed Description

**» session_id**: Session ID.

To view existing sessions in the project, call the [GET /v2team/sessions](/docs/maxirai/API/api-reference/session#list-sessions) endpoint.

**» stream**: Whether to use streaming response. If set to `true`, MAXIR AI will send answer updates to the client in real time, continuously transmitting available data. If set to `false`, the complete response will be returned at once after the answer is finished.

If not specified, the default value is `false`.

For more information on how to interpret streaming responses, refer to [Understanding Streaming Responses](/docs/maxirai/API/streaming#如何理解流式响应).

**» dataset_id**: Dataset ID associated with the job.

To query the list of datasets you have access to, call the [GET /v2/team/datasets](/docs/maxirai/API/api-reference/datasets#list-datasets) endpoint.

**» output_language**: The reply language of MAXIR AI. For example, when set to `ZH-CN`, MAXIR AI will reply in Simplified Chinese. Optional values include:

- `AUTO`: Automatically detect based on the prompt
- `EN`: English
- `ES`: Spanish
- `AR`: Arabic
- `PT`: Portuguese
- `ID`: Indonesian
- `JA`: Japanese
- `RU`: Russian
- `HI`: Hindi
- `FR`: French
- `DE`: German
- `VI`: Vietnamese
- `TR`: Turkish
- `PL`: Polish
- `IT`: Italian
- `KO`: Korean
- `ZH-CN`: Simplified Chinese
- `ZH-TW`: Traditional Chinese

**» job_mode**: Job type. Optional values include:

- `AUTO`: MAXIR AI determines whether the job is a data analytics or information retrieval task based on your question.
- `DATA_ANALYTICS`: MAXIR AI will perform data analytics based on your input.

If not specified, the session's `job_mode` setting is used.

#### Enum Values

|Property|Value|
|---|---|
|» output_language|AUTO|
|» output_language|EN|
|» output_language|ES|
|» output_language|AR|
|» output_language|PT|
|» output_language|ID|
|» output_language|JA|
|» output_language|RU|
|» output_language|HI|
|» output_language|FR|
|» output_language|DE|
|» output_language|VI|
|» output_language|TR|
|» output_language|PL|
|» output_language|IT|
|» output_language|KO|
|» output_language|ZH-CN|
|» output_language|ZH-TW|
|» job_mode|AUTO|
|» job_mode|DATA_ANALYTICS|

> Response Example

```json
{
  "code": 0,
  "data": {
    "job_id": "job-cm3ikdeuj02zk01l1yeuirt77",
    "blocks": [
      {
        "type": "CODE",
        "content": "```python\n\nimport pandas as pd\n\ndef invoke(input_0: pd.DataFrame) -> pd.DataFrame:\n    '''\n    input_0: pd.DataFrame  makeovermonday-a-century-of-global-deaths-from-disasters_decadal-deaths-disasters-type.csv\n    '''\n    # Group by 'Year' and sum the deaths for each type of disaster\n    aggregated_data = input_0.groupby('Year').sum().reset_index()\n    \n    # Select only the columns related to deaths\n    death_columns = [\n        'Deaths - Drought (decadal)', 'Deaths - Flood (decadal)', \n        'Deaths - Earthquake (decadal)', 'Deaths - Extreme weather (decadal)', \n        'Deaths - Extreme temperature (decadal)', 'Deaths - Volcanic activity (decadal)', \n        'Deaths - Wildfire (decadal)', 'Deaths - Glacial lake outburst flood (decadal)', \n        'Deaths - Dry mass movement (decadal)', 'Deaths - Wet mass movement (decadal)', \n        'Deaths - Fog (decadal)'\n    ]\n    \n    # Create a new DataFrame with the aggregated results\n    output = aggregated_data[['Year'] + death_columns]\n    \n    # Rename columns to be more descriptive\n    output.columns = ['Decade'] + [col.replace('Deaths - ', '').replace(' (decadal)', '') for col in death_columns]\n    \n    return output\n\n```",
        "group_id": "33063572-6e88-4912-8e2d-4166bcc8caee",
        "group_name": "Analyze the dataset to observe the trend of deaths caused by different types of natural disasters over the past century. This involves aggregating the data by decade and calculating the total number of deaths for each type of disaster to identify any changes in trends.",
        "stage": "Analyze"
      },
      {
        "type": "TABLE",
        "content": {
          "url": "https://static.xxx.ai/tmp_datasource_cache/code_result/cm37bchx106e301l1v9yf67yc/e24b6a5f-fdb8-48ca-ae35-dc91ac8e8ef7.csv",
          "name": "trend_data.csv",
          "expires_at": "2024-11-21T09:56:34.290544Z"
        },
        "group_id": "33063572-6e88-4912-8e2d-4166bcc8caee",
        "group_name": "Analyze the dataset to observe the trend of deaths caused by different types of natural disasters over the past century. This involves aggregating the data by decade and calculating the total number of deaths for each type of disaster to identify any changes in trends.",
        "stage": "Analyze"
      },
      {
        "type": "IMAGE",
        "content": {
          "url": "https://static.xxx.ai/tmp_datasource_cache/code_result/cm37bchx106e301l1v9yf67yc/81b75a33-a223-4954-9680-9f397872c8ad.png",
          "name": "Trend of Deaths from Natural Disasters Over the Century",
          "expires_at": "2024-11-21T09:56:34.290544Z"
        },
        "group_id": "7501680b-5879-441b-bd96-f58b1029ae17",
        "group_name": "Visualize the trend data to show how the number of deaths from different types of natural disasters has changed over the past century. Use line charts to represent the trends for each disaster type, which will help in understanding the impact of measures and technological advancements on reducing deaths.",
        "stage": "Analyze"
      },
      {
        "type": "MESSAGE",
        "content": "\n\n`Analyzing Conclusions` \n\n### Analysis of Trends in the Number of Deaths from Natural Disasters \n\n#### Data Analysis\n\n",
        "group_id": "b842aca7-6fd5-4190-85fa-97085e473877",
        "group_name": "Conclusions",
        "stage": "Respond"
      },
      {
        "type": "TABLE",
        "content": {
          "url": "https://static.xxx.ai/tmp_datasource_cache/code_result/cm37bchx106e301l1v9yf67yc/e24b6a5f-fdb8-48ca-ae35-dc91ac8e8ef7.csv",
          "name": "trend_data.csv",
          "expires_at": "2024-11-21T09:56:34.290544Z"
        },
        "group_id": "b842aca7-6fd5-4190-85fa-97085e473877",
        "group_name": "Conclusions",
        "stage": "Respond"
      },
      {
        "type": "MESSAGE",
        "content": "\n\n- **Droughts and Floods**: In the early 20th century, droughts and floods caused extremely high death tolls, particularly during the 1920s and 1930s.\n- **Earthquakes and Extreme Weather**: Earthquakes and extreme weather also led to significant death tolls throughout the century, especially in the 1970s and 1990s.\n- **Extreme Temperatures and Volcanic Activity**: These disasters had relatively lower death tolls, but in certain decades, such as the 2000s, deaths caused by extreme temperatures increased.\n\n#### Trend Visualization\n\n",
        "group_id": "b842aca7-6fd5-4190-85fa-97085e473877",
        "group_name": "Conclusions",
        "stage": "Respond"
      },
      {
        "type": "IMAGE",
        "content": {
          "url": "https://static.xxx.ai/tmp_datasource_cache/code_result/cm37bchx106e301l1v9yf67yc/81b75a33-a223-4954-9680-9f397872c8ad.png",
          "name": "Trend of Deaths from Natural Disasters Over the Century",
          "expires_at": "2024-11-21T09:56:34.290544Z"
        },
        "group_id": "b842aca7-6fd5-4190-85fa-97085e473877",
        "group_name": "Conclusions",
        "stage": "Respond"
      },
      {
        "type": "MESSAGE",
        "content": "\n\n- **Overall Trend**: The chart shows that although certain decades experienced spikes in death tolls caused by natural disasters, the overall trend is declining.\n- **Impact of Technology and Measures**: Over time, advancements in technology and the implementation of disaster prevention measures are likely key factors in reducing death tolls.\n\n#### Conclusions and Insights\n- **Technological Advancements**: Modern technological progress, such as improved early warning systems and better construction techniques, may have reduced the fatalities caused by earthquakes and extreme weather.\n- **Disaster Prevention Measures**: The enhancement of disaster prevention measures and emergency response capabilities on a global scale has likely contributed to the decreased fatality rates of natural disasters.",
        "group_id": "b842aca7-6fd5-4190-85fa-97085e473877",
        "group_name": "Conclusions",
        "stage": "Respond"
      },
      {
        "type": "SOURCES",
        "content": [
          {
            "source": "makeovermonday-a-century-of-global-deaths-from-disasters_decadal-deaths-disasters-type.csv",
            "datasource_id": "clxin6l9200oo01l1457bolx3",
            "dataset_id": "clxin6l8400ok01l1ff2m0s25",
            "file_type": "csv"
          }
        ],
        "group_id": "",
        "group_name": "",
        "stage": "Respond"
      },
      {
        "type": "QUESTIONS",
        "content": [
          "Analyze the trends in death tolls from different types of natural disasters over the past century and explore which disaster types have shown the most significant reduction in fatalities.",
          "Study the technological advancements and measures in responding to natural disasters across different regions globally, and analyze how these differences have influenced changes in death tolls in each region.",
          "Explore how future technological advancements and policy measures could further reduce fatalities caused by natural disasters, and assess their feasibility and potential impacts."
        ],
        "group_id": "-1",
        "stage": "Respond"
      }
    ]
  }
}
```

```json
{
  "code": 210021,
  "msg": "Job quota exceeded"
}
```

```json
{
  "code": 1003,
  "msg": "insufficient.authentication"
}
```

```json
{
  "code": 210020,
  "msg": "Something went wrong during job execution. Please try again."
}
```

### Response

|Status Code|Meaning|Description|Data Model|
|---|---|---|---|
|200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)|none|Inline|
|400|[Bad Request](https://tools.ietf.org/html/rfc7231#section-6.5.1)|none|Inline|
|403|[Forbidden](https://tools.ietf.org/html/rfc7231#section-6.5.3)|none|Inline|
|500|[Internal Server Error](https://tools.ietf.org/html/rfc7231#section-6.6.1)|none|Inline|

### Response Data Structure

Status Code **200**

|Name|Type|Required|Constraint|Chinese Name|Description|
|---|---|---|---|---|---|
|» code|integer|true|none||Status code. **0** means the operation was successful. Other values indicate failure. For troubleshooting, refer to [Error Codes](/docs/maxirai/API/error-codes).|
|» data|object|true|none||Job object.|
|»» job_id|string|true|none||Job ID, the unique identifier for the job in the session.|
|»» blocks|object|true|none||List of answer blocks that make up the complete answer.|
|»»» type|string|true|none||Content type of the answer block. Possible values:<br /><br />- `MESSAGE`: The content is text.<br />- `CODE`: The content is a code snippet.<br />- `TABLE`: The content is a table, with the following parameters:<br />    - `name`: The name of the `.csv` file.<br />    - `url`: The S3 Key or URL of the file.<br />    - `expires_at`: The expiration time of the `url`. To save the table for later use, make sure to download it before the URL expires.<br />- `IMAGE`: The content is an image, with the following parameters:<br />    - `name`: The name of the image.<br />    - `url`: The S3 Key or URL of the image.<br />    - `expires_at`: The expiration time of the `url`. To save the image for later use, make sure to download it before the URL expires.<br />- `SOURCE`: The content is the reference source of the answer block, with the following parameters:<br />    - `source`: The file name of the data source.<br />    - `datasource_id`: The data source ID.<br />    - `dataset_id`: The dataset ID.<br />    - `file_type`: The file extension of the data source.<br />- `QUESTIONS`: Suggested questions generated by MAXIR AI to guide your further data exploration and analysis.|
|»»» content|string|true|none||Content of the answer block, varies by `type`:<br /><br />- When `type` is `MESSAGE`, the content is a text paragraph.<br />- When `type` is `CODE`, the content is a code snippet in Markdown format.<br />- When `type` is `TABLE`, the content is a table, including the following parameters:<br />    - `name`: The name of the `.csv` file.<br />    - `url`: The S3 Key or URL of the file.<br />    - `expires_at`: The expiration time of the `url`. To save the table for later use, make sure to download it before the URL expires.<br />- When `type` is `IMAGE`, the content is an image, including the following parameters:<br />    - `name`: The name of the image.<br />    - `url`: The S3 Key or URL of the image.<br />    - `expires_at`: The expiration time of the `url`. To save the image for later use, make sure to download it before the URL expires.<br />- When `type` is `SOURCE`, the content is the reference source of the answer block, including the following parameters:<br />    - `source`: The file name of the data source.<br />    - `datasource_id`: The data source ID.<br />    - `dataset_id`: The dataset ID.<br />    - `file_type`: The file extension of the data source.<br />- When `type` is `QUESTIONS`, the content is suggested questions generated by MAXIR AI to guide your further data exploration and analysis.|
|»»» group_id|string|true|none||Group ID of the answer block.|
|»»» group_name|string|true|none||Group name of the answer block.|
|»»» stage|string|true|none||The answer generation process in MAXIR AI is divided into two stages: `Analyze` and `Respond`.  <br /><br />- The `Analyze` stage answer blocks are not part of the final answer, but are outputs during the analysis process to help you understand how the answer is generated.<br />- The `Respond` stage answer blocks are the final answers generated by MAXIR AI based on your question.|

#### Enum Values

|Property|Value|
|---|---|
|type|MESSAGE|
|type|CODE|
|type|TABLE|
|type|SOURCES|
|type|QUESTIONS|
|stage|Analyze|
|stage|Respond|

### Response Header

|Status|Header|Type|Format|Description|
|---|---|---|---|---|
|200|x-pd-trace-id|string||Trace ID returned by MAXIR AI. When an error occurs, you can provide this ID to the MAXIR AI team to assist with troubleshooting.|
