instructor icon indicating copy to clipboard operation
instructor copied to clipboard

instructor files list silently omits files after the first page

Open Mint0424 opened this issue 4 weeks ago • 0 comments

  • [x] This is a bug report.
  • [x] I searched the issue tracker and related PRs.

Model: None. This is an OpenAI Files CLI command.

Describe the bug

instructor files list prints the first page of files and exits successfully even when the Files API says has_more: true. get_files() reads .data from the SDK's cursor page. That field contains just the current page. Iterating the SDK result follows the cursor.

To Reproduce

Reproduced on main at aeb7e2558166caeec497e541bcfc6b4eaa2cf53b (Instructor 1.18.0), Python 3.12.13, macOS, and openai==3.46.0. The following runs the CLI with a mock HTTP transport. It makes no external calls.

from httpx2 import MockTransport, Response
from openai import DefaultHttpxClient, OpenAI
from typer.testing import CliRunner

from instructor.cli import files

cursors = []


def respond(request):
    cursor = request.url.params.get("after")
    cursors.append(cursor)
    first_page = cursor is None
    return Response(200, json={
        "object": "list",
        "has_more": first_page,
        "data": [{
            "id": "file-new" if first_page else "file-old",
            "bytes": 1,
            "created_at": 1700000001 if first_page else 1700000000,
            "filename": "training.jsonl",
            "object": "file",
            "purpose": "fine-tune",
            "status": "processed",
        }],
    })


with OpenAI(
    api_key="test-cli-pagination",
    base_url="https://example.test/v1",
    http_client=DefaultHttpxClient(transport=MockTransport(respond)),
) as client:
    files.client = client
    result = CliRunner().invoke(files.app, ["list"])
    print("exit:", result.exit_code)
    print("cursors:", cursors)
    print("second file displayed:", "file-old" in result.output)

Actual result: Exit code 0, cursors [None], and the second file is missing.

Expected result: The CLI follows the cursor ([None, 'file-new']) and displays both files, newest first.

Mint0424 avatar Nov 08 '26 12:11 Mint0424