Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
docs(sdk): type usd_per_credit on estimates and point to GET /v1/usage for the balance (#963)
Krisztian Gajdar768e56ba4197
diff --git a/packages/sie_sdk/src/sie_sdk/__init__.py b/packages/sie_sdk/src/sie_sdk/__init__.pyindex 535d8e217..e884c631c 100644--- a/packages/sie_sdk/src/sie_sdk/__init__.py+++ b/packages/sie_sdk/src/sie_sdk/__init__.py@@ -97,6 +97,7 @@ from sie_sdk.types import (SparseResult,StatusMessage,TimingInfo,+ UsdPerCredit,WorkerInfo,WorkerStatusMessage,)@@ -178,6 +179,7 @@ __all__ = ["SpendLimitError","StatusMessage","TimingInfo",+ "UsdPerCredit","WorkerInfo","WorkerStatusMessage","build_job_body",diff --git a/packages/sie_sdk/src/sie_sdk/types.py b/packages/sie_sdk/src/sie_sdk/types.pyindex bf1ce4a0e..9a0084bef 100644--- a/packages/sie_sdk/src/sie_sdk/types.py+++ b/packages/sie_sdk/src/sie_sdk/types.py@@ -750,8 +750,8 @@ class GenerationUsage(TypedDict):``stream_options.include_usage`` — without that there is no usage chunk atall. Native generate always carries usage on its terminal chunk. A streamwhose terminal settle did not commit in time reports its tokens without a- charge rather than guessing one. The account balance is not readable with- an API key; the console shows it.+ charge rather than guessing one. On SIE Cloud, ``GET /v1/usage`` returns the+ account balance to an API key."""prompt_tokens: int@@ -1580,6 +1580,17 @@ class AppliedRate(TypedDict):rate_denominator: int+class UsdPerCredit(TypedDict):+ """The USD price of one credit as an exact reduced rational.++ Both halves are decimal strings so a float JSON reader cannot round them:+ ``{"numerator": "1", "denominator": "100000"}`` is $0.00001 per credit.+ """++ numerator: str+ denominator: str++class RecommendedChoice(TypedDict, total=False):"""One tier's pick for a task family, with the evidence behind it."""@@ -1669,6 +1680,9 @@ class CostEstimate(TypedDict):# `null` on every non-duration-priced identity, so it is always serialized# but never meaningful outside the sealed rate card.minimum_billed_units: NotRequired[dict[str, int] | None]+ #: The USD price of one credit under the rate book that priced the quote,+ #: when the gateway reports it (SIE Cloud does).+ usd_per_credit: NotRequired[UsdPerCredit]class RateIdentity(TypedDict):diff --git a/packages/sie_sdk/tests/client/test_estimate.py b/packages/sie_sdk/tests/client/test_estimate.pyindex f4d001162..e001f0022 100644--- a/packages/sie_sdk/tests/client/test_estimate.py+++ b/packages/sie_sdk/tests/client/test_estimate.py@@ -138,6 +138,19 @@ class TestSyncEstimate:assert quote.get("estimated_credits_decimal") == expectedclient.close()+ def test_credit_price_is_returned_unchanged(self) -> None:+ usd_per_credit = {"numerator": "1", "denominator": "100000"}+ with patch("sie_sdk.client.sync.httpx.Client") as mock_client:+ mock_client.return_value.post = MagicMock(+ return_value=_resp(200, {**QUOTE, "usd_per_credit": usd_per_credit})+ )+ client = SIEClient("http://localhost:8080")++ quote = client.estimate("/v1/encode/BAAI/bge-m3", {"items": [{"text": "Hello"}]})++ assert quote.get("usd_per_credit") == usd_per_credit+ client.close()+def test_compat_body_rides_through_untouched(self) -> None:"""The model stays in the BODY for an OpenAI-compatible target."""body = {diff --git a/packages/sie_ts_sdk/src/index.ts b/packages/sie_ts_sdk/src/index.tsindex 309bd6d3b..b0a6c940d 100644--- a/packages/sie_ts_sdk/src/index.ts+++ b/packages/sie_ts_sdk/src/index.ts@@ -162,6 +162,7 @@ export type {AppliedRate,RateIdentity,CostEstimate,+ UsdPerCredit,// Model recommendation (client.recommend)RecommendOptions,RecommendedChoice,diff --git a/packages/sie_ts_sdk/src/types.ts b/packages/sie_ts_sdk/src/types.tsindex 5b13b47c2..2e7338d8e 100644--- a/packages/sie_ts_sdk/src/types.ts+++ b/packages/sie_ts_sdk/src/types.ts@@ -1499,8 +1499,8 @@ export interface ChatCompletionRequest {* stream there is no header to fall back to: without* `stream_options.include_usage` there is no usage chunk at all, and a stream* whose terminal settle did not commit in time reports its tokens without a- * charge rather than guessing one. The account balance is not readable with- * an API key; the console shows it.+ * charge rather than guessing one. On SIE Cloud, `GET /v1/usage` returns the+ * account balance to an API key.*/export interface ChatUsage {prompt_tokens: number;@@ -1726,6 +1726,17 @@ export interface AppliedRate {rate_denominator: number;}+/**+ * The USD price of one credit as an exact reduced rational.+ *+ * Both halves are decimal strings so a float JSON reader cannot round them:+ * `{ numerator: "1", denominator: "100000" }` is $0.00001 per credit.+ */+export interface UsdPerCredit {+ numerator: string;+ denominator: string;+}+/** The rate-book row set a request is priced under. */export interface RateIdentity {model: string;@@ -1767,6 +1778,8 @@ export interface CostEstimate {rounding_rule: string;estimate_basis: string;minimum_billed_units?: Record<string, number> | null;+ /** The USD price of one credit under the rate book that priced the quote, when the gateway reports it (SIE Cloud does). */+ usd_per_credit?: UsdPerCredit;}// ---------------------------------------------------------------------------diff --git a/packages/sie_ts_sdk/tests/estimate.test.ts b/packages/sie_ts_sdk/tests/estimate.test.tsindex e89fea50b..facc5f183 100644--- a/packages/sie_ts_sdk/tests/estimate.test.ts+++ b/packages/sie_ts_sdk/tests/estimate.test.ts@@ -178,6 +178,16 @@ describe("client.estimate", () => {}});+ it("returns the credit price unchanged", async () => {+ const usdPerCredit = { numerator: "1", denominator: "100000" };+ mockFetch.mockResolvedValueOnce(jsonResponse(200, { ...QUOTE, usd_per_credit: usdPerCredit }));+ const client = new SIEClient("http://localhost:8080");++ const quote = await client.estimate("/v1/encode/BAAI/bge-m3", { items: [{ text: "Hello" }] });++ expect(quote.usd_per_credit).toEqual(usdPerCredit);+ });+it("posts the envelope to /v1/estimate and returns the quote", async () => {mockFetch.mockResolvedValueOnce(jsonResponse(200, QUOTE));const client = new SIEClient("http://localhost:8080");