Skip to content

feat: add list_inference_models and estimate_inference_cost actions#44

Open
rajbhensdadiya wants to merge 3 commits into
mainfrom
keyless-inference-gateway
Open

feat: add list_inference_models and estimate_inference_cost actions#44
rajbhensdadiya wants to merge 3 commits into
mainfrom
keyless-inference-gateway

Conversation

@rajbhensdadiya

@rajbhensdadiya rajbhensdadiya commented Jul 1, 2026

Copy link
Copy Markdown
Member

Summary by CodeRabbit

  • New Features
    • Added two Floe Inference actions: list available inference models and estimate inference cost.
    • Expanded the public API with new inference schemas to support model listing and cost estimation.
  • Documentation
    • Updated action-provider documentation to reflect the increased total action count and refreshed Floe Inference action breakdown.

@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Floe Inference support to X402ActionProvider with two new Zod schemas and two new actions, re-exports the schemas from index.ts, and updates README action counts from 52 to 54 total actions.

Changes

Floe Inference feature

Layer / File(s) Summary
Inference schemas and actions
src/x402ActionProvider.ts, src/index.ts
Adds inference schemas, implements model listing and cost estimation actions, and re-exports both schemas.
README action count updates
README.md
Updates documented totals from 52/22 to 54/24 and adds the Floe Inference action breakdown.

Estimated code review effort: 2 (Simple) | ~15 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Agent
  participant X402ActionProvider
  participant FloeInferenceAPI
  Agent->>X402ActionProvider: list_inference_models()
  X402ActionProvider->>FloeInferenceAPI: GET /v1/models
  FloeInferenceAPI-->>X402ActionProvider: model list JSON
  X402ActionProvider-->>Agent: formatted model list
  Agent->>X402ActionProvider: estimate_inference_cost(model, usage)
  X402ActionProvider->>FloeInferenceAPI: POST /v1/estimate
  FloeInferenceAPI-->>X402ActionProvider: cost estimate JSON
  X402ActionProvider-->>Agent: formatted USDC estimate
Loading

Possibly related PRs

Suggested reviewers: shivamfloe, achris7, claude

Poem

A rabbit hopped through code so bright,
Two new actions took their flight.
Models listed, costs foretold,
Inference magic, USDC gold.
Hop hop hooray — now 54! 🐰

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: adding the two new actions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch keyless-inference-gateway

Comment @coderabbitai help to get the list of available commands.

@rajbhensdadiya rajbhensdadiya force-pushed the keyless-inference-gateway branch from d509ea0 to 3c0e8f9 Compare July 1, 2026 21:09
@rajbhensdadiya rajbhensdadiya marked this pull request as ready for review July 2, 2026 16:53
@achris7 achris7 requested review from Copilot and shivamfloe July 4, 2026 23:14
@achris7

achris7 commented Jul 4, 2026

Copy link
Copy Markdown
Member

@CodeRabbit review

@coderabbitai

coderabbitai Bot commented Jul 4, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two new AgentKit actions to the X402ActionProvider for Floe Inference so agents can (1) browse available inference models and (2) estimate USDC cost for a given usage vector before spending.

Changes:

  • Introduces list_inference_models and estimate_inference_cost actions + Zod schemas in X402ActionProvider.
  • Re-exports the new schemas from the package entrypoint.
  • Updates README action counts and breakdown to reflect the new actions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/x402ActionProvider.ts Adds new inference schemas and two new facilitator-backed actions for listing models and estimating inference cost.
src/index.ts Re-exports the new Zod schemas from the public entrypoint.
README.md Updates documented action counts and breakdown to include the 2 new inference actions.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/x402ActionProvider.ts Outdated
Comment thread src/x402ActionProvider.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/x402ActionProvider.ts`:
- Around line 1354-1448: Add test coverage for the new Floe Inference actions in
x402ActionProvider, focusing on listInferenceModels and estimateInferenceCost.
Cover the happy-path formatting plus the empty-model-list branch, missing
upstream_cost_usdc handling, and error/AbortError branches by mocking
facilitatorFetch/readJsonOrError. Use the action method names and CreateAction
registrations to locate the code and verify the returned strings match the
spending/formatting behavior.
- Around line 1436-1442: The Floe Inference Estimate formatter in
x402ActionProvider should not assume margin_bps is always present, since it
comes from an unvalidated JSON cast and can produce NaN%. Update the estimate
output built in the return array to handle a missing or invalid d.margin_bps by
falling back to an explicit placeholder such as — instead of formatting it as a
percentage.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: c1361665-f467-4df7-b415-5782d877476b

📥 Commits

Reviewing files that changed from the base of the PR and between 931b5a3 and 3c0e8f9.

📒 Files selected for processing (3)
  • README.md
  • src/index.ts
  • src/x402ActionProvider.ts

Comment thread src/x402ActionProvider.ts
Comment thread src/x402ActionProvider.ts
- guard estimate output against missing margin_bps (unvalidated JSON cast rendered NaN%)

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/x402ActionProvider.ts (1)

1428-1435: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Type annotation still claims margin_bps is required.

Line 1441's new guard implies margin_bps can be missing/non-finite at runtime, but the cast on line 1432 still types it as a required number. Marking it optional keeps the type honest and prevents a future refactor from treating the Line 1441 guard as dead code.

♻️ Suggested type fix
       const d = result.data as {
         model: string;
         rail: string;
         provider: string;
-        margin_bps: number;
+        margin_bps?: number;
         cost_usdc: string;
         upstream_cost_usdc?: string;
       };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/x402ActionProvider.ts` around lines 1428 - 1435, The `result.data` cast
in `x402ActionProvider` still treats `margin_bps` as always present, which
conflicts with the runtime guard later in the same flow. Update the local type
used for `d` so `margin_bps` is optional or nullable, and keep the existing
validation logic that checks it before use; use the `result.data` cast and the
`margin_bps` guard as the key symbols to locate the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@src/x402ActionProvider.ts`:
- Around line 1428-1435: The `result.data` cast in `x402ActionProvider` still
treats `margin_bps` as always present, which conflicts with the runtime guard
later in the same flow. Update the local type used for `d` so `margin_bps` is
optional or nullable, and keep the existing validation logic that checks it
before use; use the `result.data` cast and the `margin_bps` guard as the key
symbols to locate the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 88602543-ee0e-41ce-88d1-a1fe8c1d54e8

📥 Commits

Reviewing files that changed from the base of the PR and between 3c0e8f9 and 4d7ff4b.

📒 Files selected for processing (1)
  • src/x402ActionProvider.ts

- require at least one non-zero usage field in EstimateInferenceCostSchema so
  empty vectors fail at the schema instead of returning a misleading $0 estimate
- keep mixed modality units allowed: realtime models (and Gemini TTS) bill
  text + audio tokens on one rate card, so mixes must be priced server-side
- use explicit null check for context_window so a legitimate 0 still renders

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/x402ActionProvider.ts`:
- Around line 256-270: Update the estimate_inference_cost action description to
state that at least one usage field must be non-zero. Keep the existing
validation refinement unchanged and add the note to the description associated
with estimate_inference_cost.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7140a759-ab31-4750-b69f-d3333e8fecf9

📥 Commits

Reviewing files that changed from the base of the PR and between 4d7ff4b and f34db97.

📒 Files selected for processing (1)
  • src/x402ActionProvider.ts

Comment thread src/x402ActionProvider.ts
Comment on lines +256 to +270
.refine(
(a) =>
(a.inputTokens ?? 0) +
(a.outputTokens ?? 0) +
(a.cachedInputTokens ?? 0) +
(a.characters ?? 0) +
(a.audioSeconds ?? 0) +
(a.audioInputTokens ?? 0) +
(a.audioOutputTokens ?? 0) >
0,
{
message:
"Provide at least one non-zero usage field (inputTokens/outputTokens, characters, audioSeconds, or audio tokens).",
},
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Refinement logic correct; consider surfacing the constraint in the action description.

The sum > 0 check is a correct equivalent of "at least one non-zero field" given all inputs are .nonnegative() with ?? 0 fallbacks. However, since custom .refine() predicates aren't representable in JSON Schema, this constraint won't be visible to the LLM in the tool's generated schema — it'll only learn about it after a failed call. Consider adding a short note to the estimate_inference_cost action description (Lines 1418-1427) e.g. "Requires at least one non-zero usage field."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/x402ActionProvider.ts` around lines 256 - 270, Update the
estimate_inference_cost action description to state that at least one usage
field must be non-zero. Keep the existing validation refinement unchanged and
add the note to the description associated with estimate_inference_cost.

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.

3 participants