# Knowledge

The knowledge panel of one entity.

Returns the encyclopedia card of one person, place, organization or thing: its name, a short label, a short description with the article it comes from, its website and key facts. The same card comes with page 1 of a [web search](https://websearch.fast/docs/search) as `knowledge_panel`; this endpoint is for a caller that wants only the card.

`q` is the name of the entity, at most 256 bytes and 200 characters; runs of spaces become one space. `language` is detected from `q` when it is not sent.

`panel` has `title` always, and `type`, `description`, `description_url`, `description_site_name`, `website` and `attributes` (at most 30 facts as `{name: value}`, in a stable order) when they are known. `attribution` lists the open data sets the card comes from; show it with the card, and link to `description_url` when you show the description. There is no image. When no entity matches, `panel` is absent and the warning is `no_results`.

### What is charged

One `knowledge` unit when a card comes back. No card (warning `no_results`) is free, as is every error.

Units: `knowledge`. `usage.items` in the response lists them.

## Request

```
POST https://api.websearch.fast/v1/web/knowledge
```

### Body

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `q` | string | yes | The name of the entity, at most 200 characters. Runs of spaces become one space. 1 to 256 characters. |
| `language` | string |  | BCP 47 language tag. Detected from q when absent. At most 12 characters. |

### Example request

curl:

```bash
curl https://api.websearch.fast/v1/web/knowledge \
  -H "Authorization: Bearer $WEBSEARCH_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "Marie Curie"}'
```

Python:

```python
import os
import httpx

response = httpx.post(
    "https://api.websearch.fast/v1/web/knowledge",
    headers={"Authorization": f"Bearer {os.environ['WEBSEARCH_API_KEY']}"},
    json={
        "q": "Marie Curie",
    },
    timeout=60,
)
response.raise_for_status()
print(response.json())
```

TypeScript:

```typescript
const response = await fetch("https://api.websearch.fast/v1/web/knowledge", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.WEBSEARCH_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    q: "Marie Curie",
  }),
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
console.log(await response.json());
```

### Example response

```json
{
  "object": "web.knowledge",
  "request_id": "20261128120000323456789a1b2c3d4Kx7Qm2Pa",
  "created": 1795867200,
  "input": {"q": "Marie Curie"},
  "panel": {
    "title": "Marie Curie",
    "type": "Physicist",
    "description": "Marie Curie was a Polish and naturalised French physicist and chemist.",
    "description_url": "https://encyclopedia.example.org/wiki/Marie_Curie",
    "description_site_name": "Example Encyclopedia",
    "attributes": {
      "Born": "7 November 1867, Warsaw",
      "Died": "4 July 1934"
    },
    "attribution": [
      {
        "source": "Open encyclopedic data",
        "url": "https://encyclopedia.example.org/wiki/Marie_Curie",
        "license": "CC BY-SA 4.0"
      }
    ]
  },
  "usage": {"charged": true, "items": [{"unit": "knowledge", "count": 1}]}
}
```

### Response fields

The card, or no panel with the warning no_results.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `object` | string | yes | Always `web.knowledge`. |
| `request_id` | string | yes | Same as the X-Request-Id header. |
| `created` | integer | yes | Unix seconds (UTC). |
| `input` | object | yes | The parameters as applied, defaults filled in. |
| `usage` | object | yes |  |
| `usage.charged` | boolean | yes |  |
| `usage.items` | array of object | yes |  |
| `usage.items.unit` | string | yes | Billable unit, for example search_web, content_page, fetch_page, geocode, autocomplete, knowledge. |
| `usage.items.count` | integer | yes |  |
| `warnings` | array of object |  |  |
| `warnings.code` | string | yes | For example no_results, content_partial, answer_unavailable, partial, all_failed, reach_reduced. |
| `warnings.message` | string |  |  |
| `warnings.param` | string |  |  |
| `panel` | object |  | An encyclopedia card from open data. In a search it comes only on page 1 of a search with results and is included in the search price. |
| `panel.title` | string | yes |  |
| `panel.type` | string |  | Short label, for example Physicist or City. |
| `panel.description` | string |  | A short text from the encyclopedia article. |
| `panel.description_url` | string |  | The article the description comes from. |
| `panel.description_site_name` | string |  | Name of the encyclopedia, with description_url. |
| `panel.website` | string |  | Official website of the entity. |
| `panel.attributes` | object |  | Key facts as name: value, in a stable order. |
| `panel.attribution` | array of object | yes | The open data projects the data comes from, with their licences. Show it with the data. |
| `panel.attribution.source` | string | yes | Name of the open data set the fact comes from. |
| `panel.attribution.url` | string | yes |  |
| `panel.attribution.license` | string | yes | For example CC BY-SA 4.0 or CC0 1.0. |

### Errors

| Status | Codes |
| --- | --- |
| `400` | `invalid_request`, `invalid_url`, `invalid_schema` or `invalid_image`. Not charged. |
| `401` | `invalid_token`. Not charged. |
| `403` | `pre_consume_token_quota_failed` (the key's own spending limit), `access_denied`, `web_not_allowed` or `model_not_in_plan` (customer keys while plans cannot include the web tools). Not charged. |
| `404` | `not_found` or `invalid_endpoint`. Not charged. |
| `413` | `read_request_body_failed`: the request body is over the limit. Not charged. |
| `429` | `rate_limited`, `concurrency_limited`, `api_key_temporarily_frozen`, or the failure guard. Not charged. |
| `500` | `internal_error`. Not charged. |
| `503` | `source_unavailable`, `web_api_disabled`, `token_cache_busy` or `billing_busy` (the charge could not be prepared in time; retry after Retry-After). Not charged. |
| `504` | timeout. Not charged. |
