Skip to content

Search

POST /v1/search takes a question and returns passages from the sites ShinAPI tracks, best first.

POST https://api.shinapi.com/v1/search
Authorization: Bearer <your key>
Content-Type: application/json

Every search takes a key. Keys and limits says how to get one and what a search costs.

Send a JSON body.

FieldTypeDescription
querystringThe question or keywords, in Japanese or English.
max_results (optional)integerThe most passages to return.

A query holds at most 512 characters. max_results is 8 when left out and at most 32.

{
"query": "給与所得控除はいくらですか",
"max_results": 4
}
FieldTypeDescription
outcome"answered" | "no_match_in_scope" | "out_of_scope"answered: passages follow. no_match_in_scope: the index holds the question's words, and no passage holds enough of them. out_of_scope: the index holds nothing on the question.
incompletebooleanTrue when a part of the index could not be reached in time: a passage may be missing, and an outcome other than answered is not final.
resultsobject[]The passages, the best first.

Read Scope and outcomes for what to do with each outcome.

A question the index has no word of:

{
"outcome": "out_of_scope",
"incomplete": false,
"results": []
}

A query is split into its words, without particles: 令和6年分の確定申告はいつまで asks for 令和6年分, 確定 and 申告. A number stays with what it counts, and a full-width character matches its half-width form.

A passage is found by its words only when it holds more than half of them, so a long question with one matching word finds nothing that way. Those passages are ranked by how many of the words they hold, how rare each is and whether words written together in the query are together in the passage. A word in a document’s title or heading counts for more than one in its text.

A passage is also found by its meaning. The question is compared with every passage by an embedding model made for Japanese, so a question in other words than the document’s, or in English against Japanese text, finds the passage that says the same. A passage too unlike the question is left out.

What both ways found is ranked together. A second model then reads the question with each of the first passages and moves up those that answer it. When it finds none of them like the question, the search returns no passage and its outcome is no_match_in_scope.

Each entry of results is one passage.

FieldTypeDescription
titlestringThe document's title.
urlstring (uri)Where the publisher serves the document.
publisherstringWho published it, as the publisher writes its own name.
sourcestringThe source the document was read from.
document_typestringThe kind of document, such as a statute, a notice or a question and answer.
published_atstring (date) | nullThe date the publisher gives the document, or null when it gives none.
last_changed_atstring (date)The date its text was last seen to change.
licence"pdl-1.0" | "gjstu-2.0" | "cc-by-4.0" | "cc0-1.0" | "publisher-terms"The terms the passage is published under: an open licence the source is known to publish under, or publisher-terms when the publisher's own terms apply.
attributionstringThe credit line. Show it wherever the passage is shown.
tierintegerHow authoritative the source is for its topics. 1 is the highest.
textstringThe passage as published, in Markdown.

Show attribution wherever you show text. Read Sources and licences for the licence values.

A request that cannot be served answers with a status of 400 or above and this body.

FieldTypeDescription
errorstringWhat went wrong, in English.
code"invalid_request" | "unauthorized" | "payment_required" | "forbidden" | "rate_limited" | "not_found" | "internal" | "unavailable"The same fact as a fixed word a program can branch on.
StatuscodeWhen
400invalid_requestThe body is not JSON, or a field is missing or out of range. The error names it.
401unauthorizedThe key is missing, unknown or revoked.
402payment_requiredThe workspace's balance is spent. Top it up in the console.
403forbiddenThe workspace is suspended.
429rate_limitedToo many searches at once. Retry-After says how many seconds to wait.
404not_foundThe path is not served.
500internalThe search failed on our side.
503unavailableNo part of the index could be reached. Ask again.

A search that answers with an error costs nothing.