Use paginated Vast.ai v1 instances endpoint#3938
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>
|
@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? |
There was a problem hiding this comment.
Let's drop this new test file completely – the tests don't seem very useful.
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.
will post more updates when I have time to go deeper. |
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