Skip to content

Response pagination in CalypsoAI

Using our SDK, you can return paginated lists or iterate over and collect objects into a single variable.

Pagination

Lists returned in our API responses are paginated using the cursor attribute.

The cursor attribute is a pointer to the next or previous element in the list. By default, the majority of the lists return only 10 elements per page. You can set a value for the number of elements returned per page, for example:

python
from calypsoai import CalypsoAI

# Define the URL and token for CalypsoAI
CALYPSOAI_URL="https://www.us1.calypsoai.app"
CALYPSOAI_TOKEN="ADD-YOUR-TOKEN-HERE"

# Initialize the CalypsoAI client
cai = CalypsoAI(url=CALYPSOAI_URL, token=CALYPSOAI_TOKEN)

# Get the list of prompts, 10 prompts per page
prompts = cai.client.prompts.get(limit=10)

# Print the response
print(prompts.model_dump_json())

The sample request returns the following response:

json
{
  "next": "eyJyb3ciOjEwLCJsaW1pdCI6MTAsInR5cGUiOiJyb3cifQ==",
  "prev": null,
  "prompts": [
    {
      "id": "01975a7e-f050-706e-afa8-1e22f1064f21",
      "input": "Hello world",
      "result": {
        "files": null,
        "outcome": "blocked",
        "providerResult": null,
        "response": null,
        "scannerResults": [
          {
            "outcome": "failed",
            "scanDirection": "request",
            "scannerId": "019745f2-abad-700e-a805-93993f59e036",
          }
        ]
      }
    }
    (...)
  ]
}
  • If you are on the first page of the list, prev is set to null.
  • If you are on the last page of the list, next is set to null.

Iteration

If you don't want the request to return a paginated list, you can iterate over all list items instead, for example:

python
from calypsoai import CalypsoAI

# Define the URL and token for CalypsoAI
CALYPSOAI_URL="https://www.us1.calypsoai.app"
CALYPSOAI_TOKEN="ADD-YOUR-TOKEN-HERE"

# Initialize the CalypsoAI client
cai = CalypsoAI(url=CALYPSOAI_URL, token=CALYPSOAI_TOKEN)

# Iterate over all available prompts
prompts = [prompt for prompt in cai.prompts.iterate()]
  • cai.prompts.iterate(): This method iterates over all available prompts.
    Pagination is handled automatically, you don't need to manually fetch data on a page-by-page basis.
  • prompt for prompt in: This syntax loops through the data and collects every individual prompt object into the prompts list.

Updated at: