---
title: "Get Next Schedule"
method: POST
path: "/schedules/{schedule_id}/next"
---

# Get Next Schedule

`POST /schedules/{schedule_id}/next`

Generate, retain, and return exactly one next schedule for a session.

Args:
    schedule_id: Unique identifier of the generation session to advance.

Returns:
    The newly generated schedule, its zero-based index, and total retained count.

Raises:
    HTTPException: Status 404 for an unknown session, 409 while generate-all is
        active, 400 at requested-limit or solution-space exhaustion, 408/422 for
        initialization problems, or 500 for unexpected generation failures.

Behavior:
    Background conflicts are checked both before and after lazy scheduler and
    generator initialization. The shared advance path holds the session lock,
    calls ``next`` on the Z3 executor, appends serialized and original forms
    atomically, blocks duplicate models through the generator, and refreshes TTL.

## Path parameters

- `schedule_id` string, required

## Response `200`

Successful Response

- ScheduleResponse — Response model for schedule retrieval requests. **Usage:** ```python ScheduleResponse(schedule_id='...', schedule=[...], index=0, total_generated=1) ``` **Fields:** - schedule_id: Unique identifier for the schedule session - schedule: Generated schedule as `list[CourseInstanceResponse]` (typed JSON rows) - index: Index of this schedule in the generation sequence - total_generated: Total number of schedules generated so far
  - `schedule_id` string, required
  - `schedule` CourseInstanceResponse[], required
    - `course` string, required — Course id with section, e.g. `"CS101.01"`.
    - `faculty` string, required
    - `times` TimeInstanceResponse[], required
      - `day` integer, required — Weekday as `Day` enum value (1=Monday … 5=Friday).
      - `start` integer, required — Start time in minutes since midnight.
      - `duration` integer, required — Duration in minutes.
      - `delivery` 'in_person' | 'online', required — Meeting delivery mode.
    - `room` string, nullable — Assigned room when present.
    - `lab` string, nullable — Assigned lab when present.
    - `lab_index` integer, nullable — Index into `times` for the lab meeting.
    - `reserve_room_during_lab` boolean, required — Whether the lab meeting also occupies the assigned room.
  - `index` integer, required
  - `total_generated` integer, required

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/mucsci/apis/course-scheduler-api.md) · [All operations](https://skmtc.net/mucsci/apis/course-scheduler-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/mucsci/course-scheduler-api/revisions/f728bfcee693/schema)
