Conversation
Read the REST v2 SSE log streams (GET /v2/pods/{id}/logs and
GET /v2/serverless/{id}/workers/{workerId}/logs):
- get_pod_logs / get_endpoint_worker_logs return a bounded snapshot
(tail backfill plus up to max_wait seconds of live output, capped at
max_bytes with the oldest lines dropped).
- iter_pod_logs / iter_endpoint_worker_logs follow the stream, resuming
from Last-Event-ID on close or idle, and waiting out 429s on reconnect.
- get_endpoint_workers lists worker IDs for the worker log readers.
- QueryError.retry_after exposes the Retry-After header.
Refs runpod#400
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Author
|
hi my name is muhib, i am a second year waterloo math student, i thought it would be pretty cool to push a pr here as I wanted to a) find an internship for the winter b) actually try and understand how runpod works |
This branch has not been deployed
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.
Closes #400.
The REST v2 API already serves pod and worker logs as SSE streams (
GET /v2/pods/{id}/logs,GET /v2/serverless/{id}/workers/{workerId}/logs), andrunpodctl pod logswraps them. This adds the Python SDK side. It follows the bounded-snapshot shape agreed in the issue thread, plus a follow mode.API
get_pod_logs,get_endpoint_worker_logsmax_waitseconds, or once the stream has been idle that long. Pastmax_bytes(default 4 MiB) the oldest lines are dropped, so the newest output (usually the crash) is kept.iter_pod_logs,iter_endpoint_worker_logsLast-Event-ID, so lines are neither repeated nor skipped. On reconnect they retry network errors and 429s (honoringRetry-After). Errors on the first connection, and non-429 HTTP errors, raise. Optionalmax_waitcaps total time.get_endpoint_workersGET /v2/serverless/{id}/workers. Worker log readers need worker IDs, and the SDK had no way to list them.QueryError.retry_afterRetry-Afteron any REST error, orNone.rest.read_event_streamrun_rest_requestis unchanged.Arguments are validated before any request is made (
tail0–5000,sourceincontainer/system/None,sinceas an RFC3339 string or a timezone-awaredatetime). This applies to the generators too.Tests
data, UTF-8 split mid-character, an incomplete trailing event dropped), the transport, and reconnect/retry logic.tests/test_api/test_logs_server.pyruns the readers against a local fake of the log endpoints over real sockets, so the requests/urllib3 chunked-read and read-timeout behavior is exercised, not mocked. It covers the idle and busy-stream deadlines, a cut frame, the byte cap, 404,Last-Event-IDresume without gaps, a 429 on reconnect,max_wait, and the worker listing plus worker logs. It takes about 4s.ruffandpylintreport nothing on the changed modules.Not yet run against the live API. The wire format follows the published API reference and the runpod-mcp
stream-pod-logsreader.Docs: README Logs section, and
retry_afterindocs/api/handling_errors.md.🤖 Generated with Claude Code