Use paginated Vast.ai v1 instances endpoint#3938
Open
7Z0nE wants to merge 1 commit into
Open
Conversation
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>
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:
WDYT? |
r4victor
reviewed
Jun 8, 2026
Collaborator
There was a problem hiding this comment.
Let's drop this new test file completely – the tests don't seem very useful.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_instances()andget_instance(id)in the Vast.ai backend offGET /api/v0/instances/and ontoGET /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 viaafter_token/next_token.get_instances()walks pages untilnext_tokenis empty so the existing 3 s cache fills with the full list.get_instance(id)issues a targeted v1 query withselect_filters={"id": {"eq": id}}andlimit=1, so a single-row lookup stays one HTTP request instead of paginating through every owned instance.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 newtest_api_client.pycases 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.🤖 Generated with Claude Code