> ## Documentation Index
> Fetch the complete documentation index at: https://docs.rebase.energy/llms.txt
> Use this file to discover all available pages before exploring further.

# Tutorial to Get Started with Rebase API

Get started with Rebase API in a few simple steps:

<Steps>
  <Step title="Create a new site">
    Explore different [site options](/api-guides/set-up-sites).
  </Step>

  <Step title="Upload generation data">
    See also how to upload [capacity changes](/api-guides/upload-capacity).
  </Step>

  <Step title="Train ML model">
    See what [training settings](/api-guides/train-site-models) are available.
  </Step>

  <Step title="Query forecasts">
    Find out how to query [historical forecasts](/api-guides/get-forecast-historical).
  </Step>
</Steps>

## Step 1. Create a new site

Create a solar site to forecast. You will need to provide some site parameters like location, capacity, etc. More information
about the parameters for every type of site are provided in the [site set-up guides](/api-guides/set-up-sites) and in the [API Reference](/api-reference/site/create-site).

```python Create new site theme={null}
import requests

api_key = "Your API key" # Set your API key

payload = {
	"type": "solar",
	"name": "New solar site",
	"latitude": 52.5,
	"longitude": 13.4,
	"settings": {
		"model_resolution": "1h",
		"usePhysicalModels": True,
		"trainNearTermModels": False,
		"trainLongTermModels": False
	},
	"assets": [
		{
			"azimuth": 180,
			"tilt": 30,
			"capacity": 1000,
			"install_date": "2024-01-01"
		}
	]
}

url = "https://api.rebase.energy/platform/v2/sites"
headers = {"Authorization": api_key, "Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
response = response.json()
```

As response you get the ID of the newly created site.

```python Response example theme={null}
{
    "site_id": "a923653c-26f1-1b29-955d-ffde5d182276"
}
```

## Step 2. Upload generation data

To train an ML model you need to upload measured power generation data from the site. A good practice for better performance of the ML model is that the data
cover a period of one year at least with hourly or more frequent resolution.

```python Upload data theme={null}
site_id = "a923653c-26f1-1b29-955d-ffde5d182276" # This is the ID of the new site

payload = {"data": [
        {
            "valid_time": "2024-01-01T12:00:00Z",
            "value": 300.5
        },
		{
            "valid_time": "2024-01-01T13:00:00Z",
            "value": 320.2
        }
    ]
}

url = f"https://api.rebase.energy/platform/v2/sites/{site_id}/actual"

response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
response = response.json()
```

When the data have been uploaded successfully, you get a response message.

```python Response example theme={null}
{
    "message": "Actuals uploaded successfully"
}
```

## Step 3. Train ML model

To start the [training](/api-guides/train-site-models) of the ML models you will need to provide the site IDs and the training set splits.

```python Train model theme={null}
url = "https://api.rebase.energy/platform/v2/sites/models/train"

payload = {
    "site_ids": ["a923653c-26f1-1b29-955d-ffde5d182276"],
    "splits": [
        {
            "end_date": "2023-08-01T00:00Z",
            "start_date": "2023-01-01T00:00Z"
        },
        {
            "end_date": "2024-01-01T00:00Z",
            "start_date": "2023-10-01T00:00Z"
        }
    ]
}

response = requests.post(url, json=payload, headers=headers)
response.raise_for_status()
response = response.json()
```

The response message informs that the training process has started.

```python Response example theme={null}
{
    "message": "Training started"
}
```

## Step 4. Query forecast

When training is done, you can query the latest available forecast.

```python theme={null}
url = f"https://api.rebase.energy/platform/v2/sites/{site_id}/forecast"

response = requests.get(url, headers=headers)
response.raise_for_status()
response = response.json()
```

The response is a serialized table with the following columns:
<br /> `valid_time`: It contains the target times, i.e. the periods which are forecasted.
<br /> `forecast`: It contains the forecast values.
<br /> `model_name`: It contains the names of the models which create the forecasts.
<br /> `model_version`: It contains the versions of the models which create the forecasts.
<br /> `update_time`: It contains the issue/update time, i.e. the time when the forecasts were updated.

```python Response example theme={null}
{
  "valid_time": [
    "2024-01-01T00:00:00Z",
    "2024-01-01T01:00:00Z",
    "2024-01-01T02:00:00Z",
    "2024-01-01T03:00:00Z",
    "2024-01-01T04:00:00Z",
    "2024-01-01T05:00:00Z",
    "2024-01-01T06:00:00Z",
    "2024-01-01T07:00:00Z",
    "2024-01-01T08:00:00Z",
    "2024-01-01T09:00:00Z"
  ],
  "forecast": [
    6000,
    6000,
    6000,
    6000,
    6000,
    6000,
    6000,
    6000,
    6000,
    6000
  ],
  "model_name": [
    "My model",
    "My model",
    "My model",
    "My model",
    "My model",
    "My model",
    "My model",
    "My model",
    "My model",
    "My model"
  ],
  "model_version": [
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1,
    1
  ],
  "update_time": [
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z",
    "2024-01-01T00:00:00Z"
  ]
}
```
