# Upload Demand Data

## Create Model Demand

> Uploads historical demand data for a forecast model. The model must exist and belong to the authenticated organization.\
> \
> You can use any of the following content types:\
> \- \`application/json\`: A JSON object with a \`demand\` array of \`{date, demand}\` objects.\
> \- \`text/csv\`: A CSV file with lowercase headers \`date,demand\` and one row per data point.\
> \- \`application/x-ndjson\`: Newline-delimited JSON where each line is a \`{date, demand}\` object.\
> \
> The \`date\` field should be in \`YYYY-MM-DD\` format and \`demand\` must be a non-negative number.

```json
{"openapi":"3.1.0","info":{"title":"PredictHQ Forecasts API (Public Preview)","version":"1.0.0"},"tags":[{"name":"Demand Data"}],"servers":[{"url":"https://api.predicthq.com"}],"security":[{"BearerAuth":[]}],"components":{"securitySchemes":{"BearerAuth":{"type":"http","scheme":"bearer","bearerFormat":"$API_KEY","description":"Enter your PredictHQ API key. The Bearer prefix is added automatically.\n\nWhen calling the API directly, send: `Authorization: Bearer <YOUR_API_KEY>` as documented at [https://docs.predicthq.com/api/overview/authenticating](https://docs.predicthq.com/api/overview/authenticating)\n"}},"schemas":{"CreateModelDemandRequest":{"type":"object","properties":{"demand":{"description":"Array of demand data points to upload. Each item must include a date and demand value.","type":"array","items":{"$ref":"#/components/schemas/DemandInput"},"minItems":1,"title":"Demand"}},"additionalProperties":false,"required":["demand"]},"DemandInput":{"type":"object","properties":{"demand":{"description":"Number value (float or integer, must be a positive number).\n\n\nFor example, it could be units sold, room bookings, or number of staff rostered\non per day or any other unit.","type":"number","minimum":0},"date":{"description":"Expected format: `2025-02-21`","type":"string","format":"date"}},"additionalProperties":false,"required":["date","demand"]},"ErrorResponse":{"type":"object","properties":{"error":{"description":"Error message","type":"string","title":"Error"}},"required":["error"],"title":"ErrorResponse"},"HTTPValidationError":{"type":"object","properties":{"error":{"description":"Error summary message","type":"string","title":"Error"},"details":{"description":"List of validation error details","type":"array","items":{"$ref":"#/components/schemas/ValidationErrorDetail"},"title":"Details"}},"required":["error","details"],"title":"HTTPValidationError"},"ValidationErrorDetail":{"type":"object","properties":{"field":{"description":"The field that failed validation","type":"string","title":"Field"},"msg":{"description":"The validation error message","type":"string","title":"Message"},"type":{"description":"The type of validation error","type":"string","title":"Error Type"}},"required":["field","msg","type"],"title":"ValidationErrorDetail"}}},"paths":{"/v1/forecasts/models/{model_id}/demand":{"post":{"operationId":"create_demand_data","summary":"Create Model Demand","description":"Uploads historical demand data for a forecast model. The model must exist and belong to the authenticated organization.\n\nYou can use any of the following content types:\n- `application/json`: A JSON object with a `demand` array of `{date, demand}` objects.\n- `text/csv`: A CSV file with lowercase headers `date,demand` and one row per data point.\n- `application/x-ndjson`: Newline-delimited JSON where each line is a `{date, demand}` object.\n\nThe `date` field should be in `YYYY-MM-DD` format and `demand` must be a non-negative number.","parameters":[{"name":"model_id","in":"path","description":"The unique identifier of the forecast model.","required":true,"schema":{"type":"string","title":"Model Id"}},{"name":"Content-Type","in":"header","description":"Content type of the uploaded payload.","required":true,"schema":{"type":"string","enum":["text/csv","application/x-ndjson","application/json"]}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CreateModelDemandRequest"}},"application/x-ndjson":{"schema":{"description":"Newline-delimited JSON where each line is an object with date and demand.","type":"string"}},"text/csv":{"schema":{"description":"CSV with lowercase headers date,demand and multiple rows of values.","type":"string"}}}},"responses":{"201":{"description":"Successful Response"},"400":{"description":"Bad Request","content":{"application/json":{"schema":{"oneOf":[{"$ref":"#/components/schemas/ErrorResponse"},{"$ref":"#/components/schemas/HTTPValidationError"}]}}}},"401":{"description":"Unauthorized","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"402":{"description":"Payment Required","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"403":{"description":"Forbidden","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}},"404":{"description":"Not Found","content":{"application/json":{"schema":{"$ref":"#/components/schemas/ErrorResponse"}}}}},"tags":["Demand Data"]}}}}
```

## OpenAPI Spec

The OpenAPI spec for Forecasts API can be [found here](https://api.predicthq.com/docs/?urls.primaryName=Forecasts+API).

## Guides

* [Getting Started with Forecasts API](https://docs.predicthq.com/getting-started/guides/forecasts-api-guides/getting-started)
* [Understanding Forecast Accuracy Metrics](https://docs.predicthq.com/getting-started/guides/forecasts-api-guides/understanding-forecast-accuracy-metrics)
* [Troubleshooting Guide for Forecasts API](https://docs.predicthq.com/getting-started/guides/forecasts-api-guides/troubleshooting)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.predicthq.com/api/forecasts/demand-data/upload-demand-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
