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

# SDK quickstart

> From install to your first typed response in a couple of minutes.

## 1. Install and construct the client

<CodeGroup>
  ```bash npm theme={"dark"}
  npm install bridgly
  ```

  ```bash pnpm theme={"dark"}
  pnpm add bridgly
  ```
</CodeGroup>

```ts theme={"dark"}
import { Bridgly } from 'bridgly';

const client = new Bridgly({ apiKey: process.env.BRIDGLY_API_KEY });
```

## 2. Make a call

Every scraping method takes a typed request object and returns a typed result.
Here we fetch a Reddit user profile:

```ts theme={"dark"}
const res = await client.reddit.getUser({ username: 'spez' });

if (res.type === 'success') {
  console.log(res.data); // typed Reddit user profile
  console.log(res.creditsCost); // credits this call consumed
  console.log(res.timeMs); // how long it took
} else {
  console.error(res.status, res.message); // typed error
}
```

## 3. Branch on the result

Methods never throw for API or network errors. Instead they return a
discriminated union you narrow with `res.type`:

```ts theme={"dark"}
type ApiResult<T> =
  | { type: 'success'; data: T; timeMs: number; creditsCost: number }
  | { type: 'error'; status: number; message: string };
```

Once you check `res.type === 'success'`, TypeScript knows `res.data` is present
and fully typed for that endpoint. In the `error` branch you get the HTTP
`status` and a human-readable `message`.

<Tip>
  Branch on `res.status` (the numeric HTTP code) rather than matching on
  `message` — messages are meant for humans and may change. See [Errors &
  types](/sdk/errors-and-types).
</Tip>

## Try other platforms

The same shape works across every platform. Swap the namespace and method:

<CodeGroup>
  ```ts LinkedIn profile theme={"dark"}
  const res = await client.linkedin.getProfileFromUrl({
    memberIdentity: 'williamhgates',
  });
  if (res.type === 'success') console.log(res.data);
  ```

  ```ts X search theme={"dark"}
  const res = await client.x.search({ query: 'openai lang:en' });
  if (res.type === 'success') console.log(res.data);
  ```

  ```ts Reddit subreddit theme={"dark"}
  const res = await client.reddit.listSubredditPosts({
    subreddit: 'programming',
    sort: 'top',
  });
  if (res.type === 'success') console.log(res.data);
  ```
</CodeGroup>

## Next steps

<CardGroup cols={2}>
  <Card title="Functions" icon="grid-2" href="/sdk/functions">
    The full list of functions for X, Reddit, and LinkedIn.
  </Card>

  <Card title="Errors" icon="list-check" href="/sdk/errors-and-types">
    Robust, typed error handling.
  </Card>
</CardGroup>
