> ## Documentation Index
> Fetch the complete documentation index at: https://docs.raily.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Search with the SDK

> Call your search endpoint from your code with the Python or TypeScript SDK.

Call your Raily endpoint from your own code — a backend service or an agent you build —
with a typed client. Install it, add your key, and run a search.

> [card] [Python](https://docs.raily.ai/sdks/python.md)
>
> `pip install raily-ai`

> [card] [TypeScript / JavaScript](https://docs.raily.ai/sdks/javascript.md)
>
> `npm install @raily/sdk`

## Get your endpoint URL and key

An endpoint is your authenticated search URL — create one in the Raily app. It needs two
things to call: the endpoint URL and an API key.

**1. Open an endpoint**

In the Raily app, open an endpoint (or create one). Its page shows the **endpoint URL**.

**2. Create an API key**

Under **API access**, click **Create key**. The full key is shown **once** — copy it now.

**3. Set them in your environment**

Keep the key out of source control — load it from an environment variable.

```bash theme={null}
export RAILY_ENDPOINT="https://endpoints.app.raily.ai/t/your-workspace/123/mcp"
export RAILY_API_KEY="rly_..."
```

## Run your first search

```python Python theme={null}
import os
from raily import Raily

client = Raily(
    api_key=os.environ["RAILY_API_KEY"],
    endpoint=os.environ["RAILY_ENDPOINT"],
)

results = client.search("your search query", limit=5)
print(f"{len(results)} results\n")

for hit in results:
    # `fields` is a flat {name: value} map of your source's display fields
    title = hit.fields.get("title", "(untitled)")
    print(f"- {title}  (score {hit.score:.2f})")
```

```typescript TypeScript theme={null}
import { Raily } from "@raily/sdk";

const client = new Raily({
  apiKey: process.env.RAILY_API_KEY!,
  endpoint: process.env.RAILY_ENDPOINT!,
});

const results = await client.search("your search query", { limit: 5 });
console.log(`${results.length} results\n`);

for (const hit of results) {
  // `fields` is a flat { name: value } map of your source's display fields
  const title = hit.fields.title ?? "(untitled)";
  console.log(`- ${title}  (score ${hit.score?.toFixed(2)})`);
}
```

```text Output theme={null}
5 results

- Tech Giants Report Record Q1 Earnings Amid AI Investment Surge  (score 0.66)
- Researchers Achieve Breakthrough in Solid-State Battery Technology  (score 0.65)
- Scientists Discover New Deep-Sea Species Off the Coast of New Zealand  (score 0.63)
- Inside the Global Race to Map the Ocean Floor  (score 0.63)
- Global Leaders Convene for Emergency Climate Summit  (score 0.62)
```

> [!NOTE]
>
> Each result's content lives in **`fields`** — a flat `{name: value}` map of the display
> fields configured on your source (e.g. `title`, `text`, `author`, `published_date`). See
> [Reading results](#reading-results).

## Reading results

`search()` returns a list of results. Each has a `score`, the `source_collection` it came
from, and **`fields`** — a flat map of your source's display fields. Read a value by name,
or walk the whole map to see what your source exposes:

```python Python theme={null}
for hit in client.search("your search query", limit=5):
    print(f"score {hit.score:.2f}  from {hit.source_collection}")
    for name, value in hit.fields.items():
        print(f"  {name}: {value}")
```

```typescript TypeScript theme={null}
for (const hit of await client.search("your search query", { limit: 5 })) {
  console.log(`score ${hit.score?.toFixed(2)}  from ${hit.source_collection}`);
  for (const [name, value] of Object.entries(hit.fields)) {
    console.log(`  ${name}: ${value}`);
  }
}
```

## Next steps

> [card] [Python SDK](https://docs.raily.ai/sdks/python.md)
>
> Reference, async, errors, recipes

> [card] [TypeScript SDK](https://docs.raily.ai/sdks/javascript.md)
>
> Reference, errors, recipes


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.