Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions src/client/consumer/sixerr-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import type {
* signer: createLocalPaymentSigner("0x...privateKey"),
* });
*
* const response = await client.respond({ input: "Hello, world!" });
* const response = await client.respond({
* messages: [{ role: "user", content: "Hello, world!" }],
* });
* ```
*/
export class SixerrClient {
Expand All @@ -44,32 +46,33 @@ export class SixerrClient {
*/
async respond(options: RespondOptions): Promise<Response> {
const url = options.agentId
? `${this.serverUrl}/v1/responses/${options.agentId}`
: `${this.serverUrl}/v1/responses`;
? `${this.serverUrl}/v1/chat/completions/${options.agentId}`
: `${this.serverUrl}/v1/chat/completions`;

const body: Record<string, unknown> = {
model: options.model ?? "default",
input: options.input,
messages: options.messages,
};
if (options.stream) body.stream = true;
if (options.routing) body.routing = options.routing;
if (options.max_tokens) body.max_tokens = options.max_tokens;

return this.postWith402Handling(url, JSON.stringify(body), options.maxAmount);
}

/**
* Forward a full request body to the Sixerr server, handling x402 payment.
* Unlike `respond()`, this passes the body through untouched — useful for
* proxying OpenResponses requests that include fields like `instructions`,
* `tools`, `max_output_tokens`, etc.
* proxying Chat Completions requests that include fields like `tools`,
* `max_tokens`, etc.
*/
async respondRaw(
rawBody: Record<string, unknown>,
agentId?: string,
): Promise<Response> {
const url = agentId
? `${this.serverUrl}/v1/responses/${agentId}`
: `${this.serverUrl}/v1/responses`;
? `${this.serverUrl}/v1/chat/completions/${agentId}`
: `${this.serverUrl}/v1/chat/completions`;

return this.postWith402Handling(url, JSON.stringify(rawBody));
}
Expand Down
6 changes: 4 additions & 2 deletions src/client/consumer/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ export interface SixerrClientConfig {
export interface RespondOptions {
/** Model identifier. Defaults to "default". */
model?: string;
/** Input text or message array (OpenResponses format). */
input: unknown;
/** Messages array (Chat Completions format). */
messages: unknown[];
/** Enable SSE streaming. */
stream?: boolean;
/** Target a specific agent by ID. */
agentId?: string;
/** Routing strategy: "cheapest" or "fastest". */
routing?: "cheapest" | "fastest";
/** Max tokens in the completion. */
max_tokens?: number;
/** Override max USDC for this request. */
maxAmount?: string;
}
Loading