Files
magpie/internal/gateway/testdata/tinyfish/invalid_key_401.json
T
yetone ece12b370d search: TinyFish is a built-in search API (Niapyaya on X)
Niapyaya asked on X for TinyFish (tinyfish.ai) among the search APIs.
TinyFish has a plain Search API beside its browser agents, so it is added
as vendor "tinyfish", following Yuanbao Search (0804f2d97), from its own
docs (docs.tinyfish.ai/search-api/reference, /error-codes):
- GET https://api.search.tinyfish.ai/?query=<q> with X-API-Key: <key>;
  keys at agent.tinyfish.ai/api-keys (KeysURL). Its path is the root
  ("/", SearchVendor.Paths), so a base URL of the user's own works as
  every other API's does.
- The reply's results[] (title, url, snippet, date for news and some web
  pages) is read by the shared reader; snippet is its only text. It takes
  no count and answers one page of about 10, cut to the search's count.
- Errors come with their status and {"error":{code,message}}: 401 a wrong
  key, 402 INSUFFICIENT_CREDITS (the day's 12,000 free searches spent with
  an empty wallet), 429, so the next key or API is asked and the key rests
  as any other's; the message is what the user is told, the key masked.

The GUI's picker and Get key button are built from SearchVendors, so no
GUI file changes. README (en, zh), the CLI help and gateway-routing.md
name it.

Fixtures: testdata/tinyfish/search.json is the docs' example reply;
invalid_key_401.json is the real service's reply to a made-up key on
11-10. The 402 body is the docs' Search example.

Run on mote (mote-run), at the rebased head (3b261932e):
- go test -run 'Search|TinyFish|WSA|Volcengine|DeepSeek|You'
  ./internal/gateway/ ./internal/provider/ ./internal/cli/: ok (first
  run: TestSearchAPIBaseURLWithItsPath's guard caught an empty Paths;
  fixed with "/"); ./internal/gui/ ./internal/backup/ ./internal/davsync/
  with the same -run: ok
- search-api.test.cjs and searcher-pick.test.cjs (Chromium and WebKit):
  30/30 ok
- go vet -tags nogui darwin/linux/windows: ok; gofmt -l clean
- a throwaway test (not committed) asked the real api.search.tinyfish.ai
  through askSearchAPI with a made-up key: searchRefused 401 "Invalid or
  expired API key", so the address, path and key header are the ones it
  reads (a header it didn't read answers MISSING_API_KEY).

Broken by hand, each made TestTinyFishSearchAPI red: the key sent as
Authorization: Bearer instead of X-API-Key, and the "tinyfish" case
removed from askSearchAPI.

Not tried: a search with a real key (none available), so the success
reply rests on TinyFish's docs. The full go test ./... is to follow.
2026-11-10 16:47:33 +08:00

2 lines
128 B
JSON

{"error":{"code":"INVALID_API_KEY","message":"Invalid or expired API key"},"request_id":"5aa07b93-b336-4f8f-80a6-789eefce6983"}