# Generate activity time predictions

- Operation ID: `generate-time-predictions`
- HTTP method: `POST`
- Path: `/activity-time-estimator/v1/query-model`
- [Human-readable API reference](https://hub.synerise.com/api-reference/ai-suite#tag/Time-Optimizer/operation/generate-time-predictions)

## Self-contained OpenAPI method

The fenced document below contains this method's documentation and all of its local references. It is self-contained; no category or master specification fetch is required.

```yaml
openapi: 3.0.0
info:
  title: Synerise Public API
  version: 1.9.1
paths:
  /activity-time-estimator/v1/query-model:
    post:
      summary: Generate activity time predictions
      description: |
        Calculate the probability of a profile performing an activity (event) at specific times of the week.

        ---

        **API consumers:** <a href="/api-reference/authorization?tag=Authorization&amp;operationId=profileLogin" target="_blank" rel="noopener">Workspace (Business Profile)</a>, <a href="/api-reference/authorization?tag=Authorization&amp;operationId=userLogin" target="_blank" rel="noopener">Synerise User</a>

        **API key permission required:** `AI_TIME_OPTIMIZER_GET_PREDICTIONS_ANALYTICS_READ`

        **User role permission required:** `analytics_ai_time_optimizer: read`
      operationId: generate-time-predictions
      security:
        - JWT: []
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                  title: With profile ID
                  required:
                    - clientID
                  properties:
                    clientID:
                      type: array
                      maxItems: 1000
                      description: An array of profile IDs. To generate predictions for fake profiles, send empty strings as the identifiers.
                      items:
                        type: string
                        description: Profile ID
                        example: "67346"
                    mode:
                      type: string
                      description: The mode name
                      default: standard
                    timeIndex:
                      type: array
                      maxItems: 168
                      description: |
                        An array of times and time ranges to include in the predictions. If empty or omitted, the entire week is included (with the exceptions listed in `timeIndexExclude`, if they exist).

                        A time range is a two-item array. For example, `[4,7]` is the range from Monday, 03:00 to Monday, 06:59. You can mix hours and time ranges in the request.
                      example:
                        - - 0
                          - 23
                        - 24
                        - 25
                        - 26
                        - - 27
                          - 48
                      items:
                        anyOf:
                          - type: array
                            title: Hour range
                            description: A range of hours
                            minItems: 2
                            maxItems: 2
                            example:
                              - 4
                              - 7
                            items:
                              type: integer
                              title: Hour
                              description: |
                                Hour of the week.  
                                The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                                **Examples**:
                                  - Monday, 00:00 is `0`
                                  - Monday, 00:47 is `0`
                                  - Monday, 01:00 is `1`
                                  - Monday, 23:59 is `23`
                                  - Tuesday, 00:00 is `24`
                                  - Tuesday, 01:15 is `25`
                              minimum: 0
                              maximum: 167
                          - type: integer
                            title: Hour
                            description: |
                              Hour of the week.  
                              The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                              **Examples**:
                                - Monday, 00:00 is `0`
                                - Monday, 00:47 is `0`
                                - Monday, 01:00 is `1`
                                - Monday, 23:59 is `23`
                                - Tuesday, 00:00 is `24`
                                - Tuesday, 01:15 is `25`
                            minimum: 0
                            maximum: 167
                    timeIndexExclude:
                      type: array
                      maxItems: 168
                      description: |
                        An array of times and time ranges to exclude from the predictions. If empty or omitted, the entire week is included (according to the time selections made in `timeIndex`, if they exist).

                        A time range is a two-item array. For example, `[4,7]` is the range from Monday, 03:00 to Monday, 06:59. You can mix hours and time ranges in the request.
                      example:
                        - - 0
                          - 23
                        - 24
                        - 25
                        - 26
                      items:
                        anyOf:
                          - type: array
                            title: Hour range
                            description: A range of hours
                            minItems: 2
                            maxItems: 2
                            example:
                              - 4
                              - 7
                            items:
                              type: integer
                              title: Hour
                              description: |
                                Hour of the week.  
                                The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                                **Examples**:
                                  - Monday, 00:00 is `0`
                                  - Monday, 00:47 is `0`
                                  - Monday, 01:00 is `1`
                                  - Monday, 23:59 is `23`
                                  - Tuesday, 00:00 is `24`
                                  - Tuesday, 01:15 is `25`
                              minimum: 0
                              maximum: 167
                          - type: integer
                            title: Hour
                            description: |
                              Hour of the week.  
                              The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                              **Examples**:
                                - Monday, 00:00 is `0`
                                - Monday, 00:47 is `0`
                                - Monday, 01:00 is `1`
                                - Monday, 23:59 is `23`
                                - Tuesday, 00:00 is `24`
                                - Tuesday, 01:15 is `25`
                            minimum: 0
                            maximum: 167
                    topN:
                      type: integer
                      minimum: 1
                      maximum: 168
                      description: The number of best predictions to return for each profile. If omitted, predictions for every hour of the week are returned.
                - type: object
                  title: With profile UUID
                  required:
                    - clientUUID
                  properties:
                    clientUUID:
                      type: array
                      maxItems: 1000
                      description: An array of profile UUIDs. To generate predictions for fake profiles, send empty strings as the identifiers.
                      items:
                        type: string
                        description: Profile UUID
                        example: 6768085e-5925-43c6-b64f-4b90d02de8f2
                    mode:
                      type: string
                      description: The mode name
                      default: standard
                    timeIndex:
                      type: array
                      maxItems: 168
                      description: |
                        An array of times and time ranges to include in the predictions. If empty or omitted, the entire week is included (with the exceptions listed in `timeIndexExclude`, if they exist).

                        A time range is a two-item array. For example, `[4,7]` is the range from Monday, 03:00 to Monday, 06:59. You can mix hours and time ranges in the request.
                      example:
                        - - 0
                          - 23
                        - 24
                        - 25
                        - 26
                        - - 27
                          - 48
                      items:
                        anyOf:
                          - type: array
                            title: Hour range
                            description: A range of hours
                            minItems: 2
                            maxItems: 2
                            example:
                              - 4
                              - 7
                            items:
                              type: integer
                              title: Hour
                              description: |
                                Hour of the week.  
                                The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                                **Examples**:
                                  - Monday, 00:00 is `0`
                                  - Monday, 00:47 is `0`
                                  - Monday, 01:00 is `1`
                                  - Monday, 23:59 is `23`
                                  - Tuesday, 00:00 is `24`
                                  - Tuesday, 01:15 is `25`
                              minimum: 0
                              maximum: 167
                          - type: integer
                            title: Hour
                            description: |
                              Hour of the week.  
                              The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                              **Examples**:
                                - Monday, 00:00 is `0`
                                - Monday, 00:47 is `0`
                                - Monday, 01:00 is `1`
                                - Monday, 23:59 is `23`
                                - Tuesday, 00:00 is `24`
                                - Tuesday, 01:15 is `25`
                            minimum: 0
                            maximum: 167
                    timeIndexExclude:
                      type: array
                      maxItems: 168
                      description: |
                        An array of times and time ranges to exclude from the predictions. If empty or omitted, the entire week is included (according to the time selections made in `timeIndex`, if they exist).

                        A time range is a two-item array. For example, `[4,7]` is the range from Monday, 03:00 to Monday, 06:59. You can mix hours and time ranges in the request.
                      example:
                        - - 0
                          - 23
                        - 24
                        - 25
                        - 26
                      items:
                        anyOf:
                          - type: array
                            title: Hour range
                            description: A range of hours
                            minItems: 2
                            maxItems: 2
                            example:
                              - 4
                              - 7
                            items:
                              type: integer
                              title: Hour
                              description: |
                                Hour of the week.  
                                The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                                **Examples**:
                                  - Monday, 00:00 is `0`
                                  - Monday, 00:47 is `0`
                                  - Monday, 01:00 is `1`
                                  - Monday, 23:59 is `23`
                                  - Tuesday, 00:00 is `24`
                                  - Tuesday, 01:15 is `25`
                              minimum: 0
                              maximum: 167
                          - type: integer
                            title: Hour
                            description: |
                              Hour of the week.  
                              The count starts from `0` at 00:00 on Monday. The counter changes on a full hour.  
                              **Examples**:
                                - Monday, 00:00 is `0`
                                - Monday, 00:47 is `0`
                                - Monday, 01:00 is `1`
                                - Monday, 23:59 is `23`
                                - Tuesday, 00:00 is `24`
                                - Tuesday, 01:15 is `25`
                            minimum: 0
                            maximum: 167
                    topN:
                      type: integer
                      minimum: 1
                      maximum: 168
                      description: The number of best predictions to return for each profile. If omitted, predictions for every hour of the week are returned.
      responses:
        "200":
          description: Predicted activity times
          content:
            application/json:
              schema:
                oneOf:
                  - type: object
                    title: With profile ID
                    properties:
                      clientID:
                        type: array
                        maxItems: 1000
                        description: An array of profile IDs. To generate predictions for fake profiles, send empty strings as the identifiers.
                        items:
                          type: string
                          description: Profile ID
                          example: "67346"
                      hours:
                        type: array
                        description: |
                          An array of best hour prediction arrays.  

                          The array at index `0` is for the profile at index `0` in the profile list, the array at `1` is for profile `1`, and so on.
                        example:
                          - 16
                          - 32
                          - 64
                        items:
                          type: array
                          items:
                            type: integer
                            example: 17
                      predictions:
                        type: array
                        description: |
                          An array of predicted probabilities for each hour in the `hours` array.  

                          Results at index `0` are for the hours at index `0` in the `hours` array. Result at index `0` is for the hour at index `0`.  

                          Higher values mean higher probability.
                        example:
                          - 0.013318098150193691
                          - 0.012947574257850647
                          - 0.0123398806899786
                        items:
                          type: array
                          items:
                            type: number
                            format: float
                            example: 0.013318098150193691
                  - type: object
                    title: With profile UUID
                    properties:
                      clientUUID:
                        type: array
                        maxItems: 1000
                        description: An array of profile UUIDs. To generate predictions for fake profiles, send empty strings as the identifiers.
                        items:
                          type: string
                          description: Profile UUID
                          example: 6768085e-5925-43c6-b64f-4b90d02de8f2
                      hours:
                        type: array
                        description: |
                          An array of best hour prediction arrays.  

                          The array at index `0` is for the profile at index `0` in the profile list, the array at `1` is for profile `1`, and so on.
                        example:
                          - 16
                          - 32
                          - 64
                        items:
                          type: array
                          items:
                            type: integer
                            example: 17
                      predictions:
                        type: array
                        description: |
                          An array of predicted probabilities for each hour in the `hours` array.  

                          Results at index `0` are for the hours at index `0` in the `hours` array. Result at index `0` is for the hour at index `0`.  

                          Higher values mean higher probability.
                        example:
                          - 0.013318098150193691
                          - 0.012947574257850647
                          - 0.0123398806899786
                        items:
                          type: array
                          items:
                            type: number
                            format: float
                            example: 0.013318098150193691
      tags:
        - Time Optimizer
      x-snr-doc-urls:
        - /api-reference/ai-suite#tag/Time-Optimizer/operation/generate-time-predictions
      x-codeSamples:
        - lang: cURL
          label: cURL
          source: |-
            curl --request POST \
              --url https://api.synerise.com/activity-time-estimator/v1/query-model \
              --header 'Authorization: Bearer REPLACE_BEARER_TOKEN' \
              --header 'content-type: application/json' \
              --data '{"clientID":["67346"],"mode":"standard","timeIndex":[[0,23],24,25,26,[27,48]],"timeIndexExclude":[[0,23],24,25,26],"topN":1}'
        - lang: Python
          label: Python
          source: |-
            import http.client

            conn = http.client.HTTPSConnection("api.synerise.com")

            payload = "{\"clientID\":[\"67346\"],\"mode\":\"standard\",\"timeIndex\":[[0,23],24,25,26,[27,48]],\"timeIndexExclude\":[[0,23],24,25,26],\"topN\":1}"

            headers = {
                'Authorization': "Bearer REPLACE_BEARER_TOKEN",
                'content-type': "application/json"
                }

            conn.request("POST", "/activity-time-estimator/v1/query-model", payload, headers)

            res = conn.getresponse()
            data = res.read()

            print(data.decode("utf-8"))
        - lang: JavaScript
          label: JavaScript
          source: |-
            const data = JSON.stringify({
              "clientID": [
                "67346"
              ],
              "mode": "standard",
              "timeIndex": [
                [
                  0,
                  23
                ],
                24,
                25,
                26,
                [
                  27,
                  48
                ]
              ],
              "timeIndexExclude": [
                [
                  0,
                  23
                ],
                24,
                25,
                26
              ],
              "topN": 1
            });

            const xhr = new XMLHttpRequest();
            xhr.withCredentials = true;

            xhr.addEventListener("readystatechange", function () {
              if (this.readyState === this.DONE) {
                console.log(this.responseText);
              }
            });

            xhr.open("POST", "https://api.synerise.com/activity-time-estimator/v1/query-model");
            xhr.setRequestHeader("Authorization", "Bearer REPLACE_BEARER_TOKEN");
            xhr.setRequestHeader("content-type", "application/json");

            xhr.send(data);
        - lang: Node.js
          label: Node.js
          source: |-
            const http = require("https");

            const options = {
              "method": "POST",
              "hostname": "api.synerise.com",
              "port": null,
              "path": "/activity-time-estimator/v1/query-model",
              "headers": {
                "Authorization": "Bearer REPLACE_BEARER_TOKEN",
                "content-type": "application/json"
              }
            };

            const req = http.request(options, function (res) {
              const chunks = [];

              res.on("data", function (chunk) {
                chunks.push(chunk);
              });

              res.on("end", function () {
                const body = Buffer.concat(chunks);
                console.log(body.toString());
              });
            });

            req.write(JSON.stringify({
              clientID: ['67346'],
              mode: 'standard',
              timeIndex: [[0, 23], 24, 25, 26, [27, 48]],
              timeIndexExclude: [[0, 23], 24, 25, 26],
              topN: 1
            }));
            req.end();
        - lang: PHP
          label: PHP
          source: |-
            <?php

            $request = new HttpRequest();
            $request->setUrl('https://api.synerise.com/activity-time-estimator/v1/query-model');
            $request->setMethod(HTTP_METH_POST);

            $request->setHeaders([
              'Authorization' => 'Bearer REPLACE_BEARER_TOKEN',
              'content-type' => 'application/json'
            ]);

            $request->setBody('{"clientID":["67346"],"mode":"standard","timeIndex":[[0,23],24,25,26,[27,48]],"timeIndexExclude":[[0,23],24,25,26],"topN":1}');

            try {
              $response = $request->send();

              echo $response->getBody();
            } catch (HttpException $ex) {
              echo $ex;
            }
        - lang: Java
          label: Java
          source: |-
            HttpResponse<String> response = Unirest.post("https://api.synerise.com/activity-time-estimator/v1/query-model")
              .header("Authorization", "Bearer REPLACE_BEARER_TOKEN")
              .header("content-type", "application/json")
              .body("{\"clientID\":[\"67346\"],\"mode\":\"standard\",\"timeIndex\":[[0,23],24,25,26,[27,48]],\"timeIndexExclude\":[[0,23],24,25,26],\"topN\":1}")
              .asString();
servers:
  - description: Microsoft Azure EU
    url: https://api.synerise.com
  - description: Microsoft Azure USA
    url: https://api.azu.synerise.com
  - description: Google Cloud Platform
    url: https://api.geb.synerise.com
tags:
  - name: Time Optimizer
components:
  securitySchemes:
    JWT:
      type: http
      scheme: bearer
      description: |-
        JWT Bearer token. The header looks like this: `Bearer {JWT}`

        Remember to include the space between 'Bearer' and the token.

        Generate a token via the **Authorization** endpoints.
```
