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

# Use the TypeScript SDK

> Install the Leadping TypeScript SDK, configure API authentication with a Kiota request adapter, and follow an example to retrieve a lead using typed API routes.

* Package: [`@leadping/sdk`](https://www.npmjs.com/package/@leadping/sdk)
* Repository: [`leadpingai/leadping-typescript`](https://github.com/leadpingai/leadping-typescript)

## Install

```bash theme={null}
npm install @leadping/sdk @microsoft/kiota-abstractions@1.0.0-preview.103 @microsoft/kiota-http-fetchlibrary@1.0.0-preview.103
npm install --save-dev typescript @types/node
```

## Prepare the example

Use a server-side Node.js application with ES module support. This example uses `process.env` and top-level `await`; it must not be bundled into a public website with an organization key.

Set `LEADPING_API_KEY` in the process environment and replace `lead-id` with a lead from the key’s organization. The Kiota versions above match the SDK’s current dependency line. Mixing newer adapter and abstraction versions with an older SDK can produce incompatible `RequestAdapter` types. When upgrading the SDK, inspect its dependencies and update these packages together.

Save the example as `read-lead.mts`. A minimal compilation and execution command is:

```bash theme={null}
npx tsc read-lead.mts --target ES2022 --module NodeNext --moduleResolution NodeNext --types node --outDir dist
node dist/read-lead.mjs
```

Commit the dependency lockfile so another environment installs the same versions.

## Create the client

```ts theme={null}
import { createLeadpingOpenApiClient } from "@leadping/sdk";
import { ApiKeyAuthenticationProvider, ApiKeyLocation } from "@microsoft/kiota-abstractions";
import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";

const credential = process.env.LEADPING_API_KEY;
if (!credential) throw new Error("LEADPING_API_KEY is not set.");

const authProvider = new ApiKeyAuthenticationProvider(
  `Bearer ${credential}`,
  "Authorization",
  ApiKeyLocation.Header,
  new Set(["api.leadping.ai"]),
);
const client = createLeadpingOpenApiClient(new FetchRequestAdapter(authProvider));
const lead = await client.leads.byId("lead-id").get();
if (!lead) throw new Error("Leadping returned no lead.");
console.log(lead.id);
```

The client defaults to `https://api.leadping.ai`. Set `LEADPING_API_KEY` to an organization API key. `client.users.me` requires a user access token; source keys are only for lead intake.

The SDK does not store or refresh credentials. See [API Authentication](https://leadping.ai/docs/api-authentication.md).

## Call routes

```ts theme={null}
const source = await client.sources.byId("source-id").get();
```

Use generated request-body and model types from `@leadping/sdk` when creating or updating records. Confirm endpoint contracts in the [API Reference](https://leadping.ai/docs/api-reference.md), and handle `429` responses using the [rate-limit guide](https://leadping.ai/docs/rate-limits.md).

## Integrate with your application

Keep one configured client for the credential context it serves. Catch rejected requests at your job or request boundary, record a redacted status and operation, and apply the [retry policy](https://leadping.ai/docs/rate-limits.md#keep-one-retry-budget). Avoid returning a caught error as an empty lead result: callers need to distinguish “not found” from “could not authenticate.”

The generated methods return optional model properties. Check fields before rendering or using them in a business rule, and use the types from your installed package when constructing a request body.


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