# Client

> Consume 402-gated APIs from TypeScript with createPayKitClient — a payment-aware fetch that pays and retries automatically.

Unlike the server-only SDKs in other languages, TypeScript also ships the **paying side**, via `@solana/pay-kit/client`. `createPayKitClient` returns a `fetch`-shaped client: on a `402` it reads the challenge, pays with the matching protocol, and retries the request with the `Authorization: Payment` credential.

## Create a client

```ts
import { createPayKitClient } from '@solana/pay-kit/client';
import { createKeyPairSignerFromBytes, getBase58Encoder } from '@solana/kit';
```

<Snippet name="charge.client" url="https://api.example.com/api/v1/quote/AAPL" />

`createPayKitClient` takes the wallet `signer` (an `@solana/kit` `KeyPairSigner`), an `rpcUrl`, and an optional `accept` preference list. The returned `client.fetch` mirrors the platform `fetch`.

## Force a protocol

When an endpoint advertises both MPP and x402, pass the protocol as the third argument to pin the rail. Omit it to let pay-kit choose.

<Snippet name="x402.client" url="https://api.example.com/api/v1/quote/AAPL" />

## Streamed sessions

For a [session](/docs/sdk/typescript/schemes#session) endpoint, open a payment channel and consume the stream chunk by chunk. The opener signs each off-chain voucher as deliveries arrive; settlement runs on the server when the channel closes.

<Snippet name="session.client" url="https://api.example.com/api/v1/stream" />
