GPT ignores pagination instructions for API endpoints

My API returns paginated data, especially the latest_prices endpoint. The latest_connections endpoint usually only returns one page. I have put that in the OpenAPI spec, I have even provided an example:

openapi: 3.0.0
info:
  title: xxx API
  version: 2
  description: xxx API V2
servers:
  - url: https://backend.xxx.ch/
paths:
  /api/xxx/v2/latest_connection:
    get:
      operationId: getLatestConnectionListView
      summary: Get latest connection
      description: >
        This endpoint takes a constant query_id (ID=7) and a desired departure date to return a list of possible
        connections.
      tags:
        - latest_connection
      parameters:
        - name: query_id
          in: query
          required: true
          schema:
            type: integer
            default: 7
          description: Constant query_id parameter with a default value of 7.
        - name: departure
          in: query
          required: true
          schema:
            type: string
            format: date
          description: Desired departure date in YYYY-MM-DD format.
      responses:
        "200":
          description: A list of possible connections based on the provided query_id and departure date.
          content:
            application/json:
              schema:
                type: object
                properties:
                  current_page:
                    type: integer
                  next_page:
                    type: "null"
                    description: The pointer to the next page for paginated data. If "null", the end has been reached.
                  page_size:
                    type: integer
                  previous_page:
                    type: "null"
                  results:
                    type: array
                    items:
                      type: object
                      properties:
                        changes:
                          type: integer
                        created_at:
                          type: string
                          format: date-time
                        departure:
                          type: string
                          format: date-time
                        desired_dst_canonical_name:
                          type: string
                        desired_dst_de:
                          type: string
                        desired_src_canonical_name:
                          type: string
                        desired_src_de:
                          type: string
                        duration:
                          type: string
                        id:
                          type: integer
                        traintypes:
                          type: string
                        updated_at:
                          type: string
                          format: date-time
                        via:
                          type: "null"
                  total_count:
                    type: integer
                  total_pages:
                    type: integer
  /api/xxx/v2/latest_prices:
    get:
      operationId: getLatestPricesListView
      summary: Get latest prices
      description: >
        Takes a connection_id and returns a paginated list of offers with associated prices. Clients should monitor the
        `next_page` attribute in the response to determine if additional data is available and to fetch subsequent
        pages. Ignoring this attribute may result in incomplete data retrieval.
      tags:
        - latest_prices
      parameters:
        - name: connection_id
          in: query
          required: true
          schema:
            type: integer
          description: ID of the connection for which prices are being queried.
        - name: page
          in: query
          required: true
          schema:
            type: integer
          description: the page number to fetch
          default: 1
        - name: page_size
          in: query
          required: true
          schema:
            type: integer
          description: the number of items per page to fetch
          default: 50
      responses:
        "200":
          description: A list of offers with associated prices for the given connection ID.
          content:
            application/json:
              schema:
                type: object
                properties:
                  current_page:
                    type: integer
                  next_page:
                    type: string
                    nullable: true
description: >
  Provides the URL for the next page of results. This field is `null` if there are no more pages. Always check this
  attribute to ensure complete data collection.
              page_size:
                type: integer
              previous_page:
                type: string
                nullable: true
              results:
                type: array
                items:
                  type: object
                  properties:
                    crawler_engine:
                      type: string
                    created_at:
                      type: string
                      format: date-time
                    gender:
                      type: string
                    id:
                      type: integer
                    price:
                      type: integer
                    price_currency:
                      type: string
                    price_type:
                      type: string
                    seat_type:
                      type: string
                    subscription_card:
                      type: string
                      description: Information about the subscription / discount card to which the price is applying
                    updated_at:
                      type: string
                      format: date-time
                    vendor_link:
                      type: string
                      format: uri
              total_count:
                type: integer
              total_pages:
                type: integer
        example:
          current_page: 1
          next_page: "/api/xxx/v2/latest_prices?page=2&page_size=10&connection_id=1244872"
          page_size: 10
          previous_page: null
          results: [...]
          total_count: 100
          total_pages: 10

Also, in the instructions, I have explicitly told to fetch all pages:

When interacting with the API for fetching both connections and prices, if the initial response has a next_page attribute that is not null, indicating more pages of data are available, the GPT will repeatedly call the API, passing the next_page value each time, until it fetches all pages. This process is essential for ensuring that all available information is collected before presenting the findings to the user. This meticulous attention to fetching all paginated data ensures users receive comprehensive and detailed responses.

Still, the GPT completely ignores this. I only ever fetches the first page. What am I doing wrong?

I was having the same issue, actually, and was hoping for an update on your post, but I managed to solve it. I created a (.txt) file with the instructions and uploaded it to the assistant. Then I told it to read this file before every GET request and follow the steps. Inside the file, I included the steps for pagination, and it worked.

@pedro.vieira can you please share an example of such instructions?

That sounds like a funny hack. I would also be interested in your specific instructions.

I uploaded a .txt with this instructions

When you make a GET request, you must ensure that you have checked all pages before returning a response to the user:

Step 1 - You will make a request with a pageSize equal to 50.
Step 2 - After making the request, you will check if the response has next_page_url = null. If it does not, you will take the pageToken from the response and make a new request to fetch the next page.
Step 3 - You will receive a new response, and you will check again if the next_page_url = null. If it is null, you will return the response to the user. If it is not, you repeat Steps 1 and 2 until you have checked all the pages.
Step 4 - Do not return the response to the user unless the next_page_url is null, unless they specifically request a particular page.

NEVER RETURN THE RESPONSE TO THE USER UNLESS next_page_url IS null, unless they request a specific page.

I pass in portuguese, because i’m building an assistant in my job, so i didn’t test with this instructions in english, but in portuguese work well.

OBS: this assistant makes the request in twilio’s API

1 Like