Skip to content

Use paginated Vast.ai v1 instances endpoint#3938

Open
7Z0nE wants to merge 1 commit into
dstackai:masterfrom
7Z0nE:vastai-v1-instances-pagination
Open

Use paginated Vast.ai v1 instances endpoint#3938
7Z0nE wants to merge 1 commit into
dstackai:masterfrom
7Z0nE:vastai-v1-instances-pagination

Conversation

@7Z0nE

@7Z0nE 7Z0nE commented Jun 5, 2026

Copy link
Copy Markdown

Summary

  • Move get_instances() and get_instance(id) in the Vast.ai backend off GET /api/v0/instances/ and onto GET /api/v1/instances/. Vast.ai's April 2026 product update announces that the v0 list endpoint will start returning paginated results (max 25 per response), so callers must handle the keyset cursor. The v1 endpoint already enforces that contract via after_token / next_token.
  • get_instances() walks pages until next_token is empty so the existing 3 s cache fills with the full list.
  • get_instance(id) issues a targeted v1 query with select_filters={"id": {"eq": id}} and limit=1, so a single-row lookup stays one HTTP request instead of paginating through every owned instance.
  • Other Vast.ai endpoints used by the backend — PUT /asks/{id}/ (create), DELETE /instances/{id}/ (destroy), POST /bundles/ (search offers), PUT /instances/request_logs/{id}/ — have no v1 replacement in the published OpenAPI yet, so they remain on v0.

Test plan

  • uv run pytest src/tests/_internal/core/backends/vastai/ -v — 15 passed (4 new test_api_client.py cases cover pagination, single-instance filter, 404 handling, and that destroy still hits v0).
  • uv run pytest src/tests/_internal/core/backends/ -q — 244 passed (no regressions in sibling backends).
  • uv run pre-commit run --files <changed> — ruff/format clean.
  • Smoke test against a real Vast.ai account (would appreciate a maintainer doing this — I do not have credentials).

🤖 Generated with Claude Code

The v0 GET /instances/ endpoint will start returning paginated results
(max 25 per page) per Vast.ai's April 2026 product update. Move the
list-instances and single-instance lookups to /api/v1/instances/, which
already enforces pagination via the after_token/next_token keyset
cursor.

get_instances() now walks pages until next_token is empty.
get_instance(id) uses select_filters={"id":{"eq":id}} so a single-row
lookup stays one request instead of paginating through every owned
instance. Other Vast.ai endpoints (asks, destroy, bundles, logs) stay
on v0 — they have no v1 replacement yet.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@r4victor

r4victor commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

@7Z0nE, thanks for the PR. The change looks solid and can be merged. Although I'm not sure if we need get_instances() and thus _list_instances_v1() and the cache at all since it's used only for get_instance(). Apparently, it was needed when there was no show-instance API. I'm happy with either of these:

  • Drop get_instances() and _list_instances_v1() and the cache in favor of show-instance.
  • Implement get_instance() via _list_instances_v1() as you did but drop get_instances().
  • Keep the PR as is in case get_instances() is useful in future.

WDYT?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop this new test file completely – the tests don't seem very useful.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

@7Z0nE

7Z0nE commented Jun 16, 2026

Copy link
Copy Markdown
Author

I'm not sure if we need get_instances() and thus _list_instances_v1() and the cache at all since it's used only for get_instance(). Apparently, it was needed when there was no show-instance API

The show-instance API (GET /api/v0/instances/{id}) still has a "v0" in the path. Requests to this v0 endpoint will not work with API keys generted from the new v1 endpoints. Thus we cannot use show-instance and need to keep the workaround with the v1/instances endpoint (https://docs.vast.ai/api-reference/instances/show-instances).

I will test this again to clarify. If it works, then I would do a simplification.

Drop get_instances() and _list_instances_v1() and the cache in favor of show-instance.
I assumed that get_instances is called by users of the VastAiAPIClient and therefore needs to be supported.
A possibility I see would be to migrate all usages to list_instances with a pagination interface.

will post more updates when I have time to go deeper.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants