feat(generations): history() and get() with cost, prompt and inputs - #14
Merged
Merged
Conversation
generations.list() returned only the output URL and model, so there was no SDK way to see what a request cost or what it was called with. Wrap the existing /inference-request/request-history endpoints: - generations.history(): one row per request, failures included, with credits_deduction, request_body, status, latency; date/model/status/user filters and sort by cost. - generations.get(request_id): one request by id, of any age. Also documents the cost/status/prompt/parameters fields that list() rows gain from the companion spot-backend change.
…ield availability - get() resolves only the caller's own requests; a teammate's id from history() is a 404. - history() repeats a multi-output request once per output, each row with the full cost, so de-dupe on request_id before summing. - list()'s new fields need spot-backend-k8s#348; read them with .get().
Merged
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.
Why
M&S (Enrique) on Discord: "python sdk how do we get cost, prompt, etc.?" —
segmind.generations.list(page=1)only returnsid / request_id / generation_url / model_name / user_* / timestamps.The data already exists behind
/inference-request/request-history(cost, request_body, status, latency, errors), which acceptsx-api-key— the SDK just never wrapped it.What
generations.history(...)→GET /request-history. One row per request (failures + pending included). Params:page,per_page(1–100),from_date/to_date(≤31 days, server default last 7),model_name,status,user_id/user_email,sort_by(credits_deductionfor most-expensive-first),sort_order. Only non-empty filters are sent.generations.get(request_id)→GET /request-history/<id>, not date-bounded. Id is URL-quoted into one path segment.segmind.generations.history/getdelegates.docs/api/generations.rstfield list (replaces the old vague "Input parameters / Output data" bullets), examples inexamples.md+docs/examples.rst, CHANGELOG under Unreleased.list()itself is unchanged client-side; its rows gainstatus / credits_deduction / latency_ms / prompt / parametersfrom segmind/spot-backend-k8s#348.Verification
pytest— 301 passed, 7 skipped (7 new tests intests/test_generations.py).history(per_page=2)returnedseedance-2.0-mini COMPLETED 0.0886165 {'prompt': 'A lantern swings…'};get(<that request_id>)returned the same row.🤖 Generated with Claude Code