Skip to content

feat(generations): history() and get() with cost, prompt and inputs - #14

Merged
shrey-rajvanshi merged 4 commits into
mainfrom
shrey/generations-history-cost-prompt
Sep 23, 2026
Merged

shrey-rajvanshi merged 4 commits into
mainfrom
shrey/generations-history-cost-prompt

Conversation

@shrey-rajvanshi

Copy link
Copy Markdown
Contributor

Why

M&S (Enrique) on Discord: "python sdk how do we get cost, prompt, etc.?" — segmind.generations.list(page=1) only returns id / request_id / generation_url / model_name / user_* / timestamps.

The data already exists behind /inference-request/request-history (cost, request_body, status, latency, errors), which accepts x-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_deduction for 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.
  • Module-level segmind.generations.history/get delegates.
  • Docs: docs/api/generations.rst field list (replaces the old vague "Input parameters / Output data" bullets), examples in examples.md + docs/examples.rst, CHANGELOG under Unreleased.

list() itself is unchanged client-side; its rows gain status / credits_deduction / latency_ms / prompt / parameters from segmind/spot-backend-k8s#348.

Verification

  • pytest — 301 passed, 7 skipped (7 new tests in tests/test_generations.py).
  • Live against prod with an API key: history(per_page=2) returned seedance-2.0-mini COMPLETED 0.0886165 {'prompt': 'A lantern swings…'}; get(<that request_id>) returned the same row.

🤖 Generated with Claude Code

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().
@shrey-rajvanshi
shrey-rajvanshi merged commit df3dfd6 into main Sep 23, 2026
6 checks passed
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.

1 participant