Skip to content

Let a catalog search name a scope without a query - #17

Merged
kev1n merged 1 commit into
mainfrom
search-scope-without-query
Sep 5, 2026
Merged

Let a catalog search name a scope without a query#17
kev1n merged 1 commit into
mainfrom
search-scope-without-query

Conversation

@kev1n

@kev1n kev1n commented Sep 5, 2026

Copy link
Copy Markdown
Member

What was broken

The gateway's ranked search requires at least one of q, category, platform, in any combination. Measured against production today:

/catalog/search?platform=reddit   -> 200
/catalog/search?category=social   -> 200
/catalog/search                   -> 400 {"error":"name q, category, or platform"}

The CLI was stricter. search took the query positionally and AnyApiClient.search unconditionally called url.searchParams.set('q', options.query), so "every reddit API" was expressible over MCP and over curl but impossible through anyapi search. Gateway PR getanyapi-com/anyapi#1013 relaxed the MCP side; the CLI was never updated.

What changed

  • anyapi search [query] - the query argument is now optional, and --category <category> / --platform <platform> join it. The flag shape follows the existing anyapi list --category, not a new convention.
  • AnyApiClient.search omits q entirely when there is no query. It never sends it empty.
  • A search naming none of the three is rejected in the client with Search needs a query, --category, or --platform. and never reaches the gateway.
  • The bundled anyapi-discover skill and the README document the scope form, since this command's documented usage changed.

anyapi search reddit is unchanged. No limit, default, or cap was introduced.

The tolerant-reader rules are untouched: readSearchResponse still rejects credit keys and any provider that is not "AnyAPI", and nothing derives or repairs relationships among returned fields.

Proof

Gate, on this branch:

$ npm run build && npm test
Test Files  11 passed (11)
     Tests  100 passed (100)

$ npm run canary:live
Live discovery canary passed: 363 catalog APIs, 1 search result, ahrefs.backlinks public schema.

Both new tests were confirmed red against the pre-fix search body:

x scopes a search without a query and omits q rather than sending it empty
  -> expected { q: 'undefined', platform: 'reddit' } to deeply equal { platform: 'reddit' }
x rejects a search naming no query, category, or platform without calling the gateway
  -> expected [Function] to throw error including 'Search needs a query, --category, or ...'

Live against https://api.getanyapi.com, from the built CLI:

$ node dist/index.js search --platform reddit
sku                       name                      price
reddit.post               Reddit Post               from USD 1.20/1k req
reddit.post_comments      Reddit Post Comments      from USD 2.00/1k req
reddit.post_transcript    Reddit Post Transcript    from USD 2.00/1k req
reddit.profile            Reddit Profile            from USD 1.20/1k req
reddit.search             Reddit Search             from USD 1.20/1k req
reddit.subreddit_details  Reddit Subreddit Details  from USD 1.20/1k req
reddit.subreddit_posts    Reddit Subreddit Posts    from USD 0.90/1k req
reddit.subreddit_search   Reddit Subreddit Search   from USD 0.90/1k req
reddit.trending_posts     Reddit Trending Posts     from USD 0.36/1k req
reddit.user_comments      Reddit User Comments      from USD 1.20/1k req
reddit.user_posts         Reddit User Posts         from USD 0.90/1k req

$ node dist/index.js search --category social      # 5 of many
bluesky.post              Bluesky Post              from USD 2.00/1k req
bluesky.profile           Bluesky Profile           from USD 2.00/1k req
bluesky.user_posts        Bluesky User Posts        from USD 2.00/1k req
douyin.profile            Douyin Profile            from USD 1.20/1k req
douyin.user_posts         Douyin User Posts         from USD 1.20/1k req

$ node dist/index.js search reddit                 # unchanged, ranked
reddit.search             Reddit Search             from USD 1.20/1k req
reddit.subreddit_search   Reddit Subreddit Search   from USD 0.90/1k req

$ node dist/index.js search
Search needs a query, --category, or --platform.   # exit 1, no request sent

Not in this PR

No version bump, tag, or npm publish. Releasing is a separate decision.

The sibling fix for the n8n node is in getanyapi-com/n8n-nodes-anyapi.

🤖 Generated with Claude Code

The gateway's ranked search accepts any non-empty combination of q,
category and platform, so /catalog/search?platform=reddit is a 200. The
CLI could not express that: `search` took the query positionally and
`AnyApiClient.search` unconditionally set `q`, so "every reddit API" was
reachable over MCP and over curl but not over `anyapi search`.

The query argument is now optional and `--category`/`--platform` join it,
following `list --category` rather than inventing a new flag shape.
`anyapi search reddit` is unchanged. An absent query is omitted from the
query string rather than sent empty, and a search naming none of the
three is rejected in the client with a clear message instead of being
sent to the gateway to earn a 400.

The bundled anyapi-discover skill and the README document the scope form,
because they document this command's usage.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@kev1n
kev1n merged commit 5666da8 into main Sep 5, 2026
2 checks passed
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.

1 participant