-
Notifications
You must be signed in to change notification settings - Fork 7
Description
The /credits HTTP endpoint returns credit data as expected, but the TypeScript SDK’s credits.getCredits() method returns an effectively empty object because the Zod schema is defined as {}.
What I’m seeing
Direct HTTP call works:
curl https://openrouter.ai/api/v1/credits \
-H "Authorization: Bearer sk-xxxx"Response:
{
"data": {
"total_credits": 10,
"total_usage": 0
}
}But using the SDK:
import { OpenRouter } from "@openrouter/sdk";
const client = new OpenRouter({ apiKey: process.env.OPENROUTER_API_KEY! });
const result = await client.credits.getCredits();
console.log(result); // {}The logged result is just {} (or an essentially empty object), with none of the data.total_credits / data.total_usage fields from the API.
Likely cause
In the published typings:
// node_modules/@openrouter/sdk/esm/models/operations/getcredits.d.ts
/**
* Total credits purchased and used
*/
export type GetCreditsResponse = {};And the inbound Zod schema is defined against that empty shape, so the response body is parsed into {} and all fields from the JSON payload are discarded before being returned by credits.getCredits().
Meanwhile, the generated request code clearly expects a JSON body for 200 responses:
// node_modules/@openrouter/sdk/esm/funcs/creditsGetCredits.js
const [result] = await M.match(
M.json(200, operations.GetCreditsResponse$inboundSchema),
...
)(response, req, { extraFields: responseFields });Because GetCreditsResponse$inboundSchema is an empty object schema, the actual fields are never surfaced to the caller.
Expected behavior
client.credits.getCredits() should return a typed object that exposes the same data fields the HTTP API returns, e.g.:
type GetCreditsResponse = {
data: {
total_credits: number;
total_usage: number;
// any other documented fields
};
};Then:
const result = await client.credits.getCredits();
console.log(result.data.total_credits); // 10
console.log(result.data.total_usage); // 0Actual behavior
- The API response has the expected data under
data. - The SDK’s
credits.getCredits()returns an object typed as{}(and effectively empty at runtime when inspected).
Environment
@openrouter/sdkversions in project:- direct:
@openrouter/[email protected] - via
@openrouter/[email protected]→@openrouter/[email protected]
- direct:
- Node:
v25.1.0 - TypeScript:
5.9.3 - tsx:
4.20.6 - TS config:
strictwithexactOptionalPropertyTypes: true
Suggested fix
- Update
GetCreditsResponseand its Zod inbound schema to match the actual JSON structure returned by/credits(at least includingdata.total_creditsanddata.total_usage). - Optionally add proper types for the
dataobject so SDK users can rely on them instead of casting toanyor hitting the HTTP endpoint manually.