feat(opencode): route websearch Exa through Kilo proxy - #12470
Merged
marius-kilocode merged 1 commit intoJul 29, 2026
Conversation
Add a new Kilo-REST Exa transport alongside the existing MCP-Exa and MCP-Parallel transports. When the websearch tool picks the Exa provider and the user is signed into Kilo, requests go to https://app.kilo.ai/api/exa/search with the user's Kilo bearer. The cloud proxy injects its own Exa API key; the client sends the user's Kilo API key as a Bearer token. The MCP-BYOK path (EXA_API_KEY) and MCP-unauthed fallback are preserved unchanged. Changes: * New `packages/opencode/src/kilocode/tool/websearch-kilo-exa.ts` implements `callKiloExa` against the Exa REST API (`POST /search`) with `{ highlights: true }` contents and clamps numResults at 10 (Exa's first-10-results flat $0.007 tier). * `packages/opencode/src/tool/websearch.ts` adds a `"kilo-exa"` provider variant (selected only via `KILO_WEBSEARCH_PROVIDER` override), an Auth.Service yield to source the Kilo bearer, a transport-dispatch block that prefers Kilo-REST over MCP when auth is available and EXA_API_KEY is unset, and `transport` metadata on the tool part. MCP-Exa numResults is now clamped at 10 (default stays 8). * 13 unit tests in `packages/opencode/test/kilocode/tool/websearch-kilo-exa.test.ts` cover request shape, response formatting, error handling, and the costDollars ignore case. * Parameters snapshot updated for the new numResults description string. * Patch-level changeset added.
marius-kilocode
approved these changes
Jul 29, 2026
marius-kilocode
left a comment
Collaborator
There was a problem hiding this comment.
Tested end to end against the live backend: unit tests and typecheck pass, direct client calls to api.kilo.ai/api/exa/search return highlighted results with the numResults clamp working, and a full kilo run session routes Exa search through the Kilo proxy with the stored oauth token. Cloud side has been live with auth, free allowance, and credit billing for months. LGTM.
Collaborator
|
Thanks for this one @IamCoder18 |
This was referenced Jul 29, 2026
unixcrh
pushed a commit
to unixcrh/kilocode
that referenced
this pull request
Aug 1, 2026
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
t7tran
pushed a commit
to t7tran/kilocode
that referenced
this pull request
Aug 14, 2026
Add a new Kilo-REST Exa transport alongside the existing MCP-Exa and MCP-Parallel transports. When the websearch tool picks the Exa provider and the user is signed into Kilo, requests go to https://app.kilo.ai/api/exa/search with the user's Kilo bearer. The cloud proxy injects its own Exa API key; the client sends the user's Kilo API key as a Bearer token. The MCP-BYOK path (EXA_API_KEY) and MCP-unauthed fallback are preserved unchanged. Changes: * New `packages/opencode/src/kilocode/tool/websearch-kilo-exa.ts` implements `callKiloExa` against the Exa REST API (`POST /search`) with `{ highlights: true }` contents and clamps numResults at 10 (Exa's first-10-results flat $0.007 tier). * `packages/opencode/src/tool/websearch.ts` adds a `"kilo-exa"` provider variant (selected only via `KILO_WEBSEARCH_PROVIDER` override), an Auth.Service yield to source the Kilo bearer, a transport-dispatch block that prefers Kilo-REST over MCP when auth is available and EXA_API_KEY is unset, and `transport` metadata on the tool part. MCP-Exa numResults is now clamped at 10 (default stays 8). * 13 unit tests in `packages/opencode/test/kilocode/tool/websearch-kilo-exa.test.ts` cover request shape, response formatting, error handling, and the costDollars ignore case. * Parameters snapshot updated for the new numResults description string. * Patch-level changeset added.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue
Closes #12469
Context
The
websearchtool currently has no integration with Kilo auth. When the session routes to the Exa provider, requests fall through to the publichttps://mcp.exa.ai/mcpendpoint, unauthenticated by default, or viaEXA_API_KEYquery-param BYOK if the user set it. Kilo-authenticated users have no way to route web searches through their Kilo account, and there's no env override to force a Kilo-billed transport.This adds a third transport:
kilo-rest, that POSTs tohttps://app.kilo.ai/api/exa/searchwith the user's Kilo API key as a Bearer token. The cloud proxy injects its own Exa API key server-side. Result clamping at 10 is added across all Exa transports to keep cost predictable (Exa's first 10 results are $0.007 flat).Implementation
callKiloExalives inpackages/opencode/src/kilocode/tool/websearch-kilo-exa.ts. It posts a small JSON body with the query, type, numResults, and a highlights-only contents field to Exa's REST search endpoint via the supplied HTTP client, decodes the response into a numbered title/url/date/highlight block, clamps numResults at 10, and dies on 401/403/5xx/timeout with actionable messages.The upstream change to
packages/opencode/src/tool/websearch.tsis small. Add kilo-exa to the provider enum so the env override is routable, yield Auth.Service to source the Kilo bearer, compute a transport with the precedence below, and dispatch to callKiloExa when transport is kilo-rest, otherwise the existing callProvider runs unchanged. mcp-websearch.ts and websearch.txt are not touched.Screenshots / Video
Full conversation:
https://app.kilo.ai/s/a7257bae-8a45-48ac-a916-ce55c2a30779
How to Test
kilo auth login.websearchtool with any query.Checklist
Get in Touch
Discord: @IamCoder18