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

# API client

> An authenticated HTTP client for the cskn API.

`api` is a small wrapper around a preconfigured axios instance. It points at `https://api.csknapps.xyz/api`, attaches the user's credentials to every request, and resolves with the response body.

```tsx theme={null}
import { api } from '@cskn/sdk';

const posts = await api.get<Post[]>('/apps/blog/posts', { limit: 20 });
const created = await api.post<Post>('/apps/blog/posts', { title: 'Hello' });
await api.put('/apps/blog/posts/42', { title: 'Hello again' });
await api.patch('/apps/blog/posts/42', { pinned: true });
await api.delete('/apps/blog/posts/42');
```

| Method | Signature | Notes |
| - | - | - |
| `get` | `get<T>(url, params?)` | `params` becomes the query string. |
| `post` | `post<T>(url, body?)` | |
| `put` | `put<T>(url, body?)` | Replaces the resource. |
| `patch` | `patch<T>(url, body?)` | Changes some fields. Prefer it over `put` when another device may be editing the same record. |
| `delete` | `delete<T>(url)` | |

## Credentials

You do not set headers yourself.

* **In a shell**, `useBridgeAuth` stores the token from the bridge, and every request carries `Authorization: Bearer <token>`.
* **In a signed-in browser**, `useBridgeAuth` switches the base URL to your own origin's `/api` proxy, which reads the session cookie and forwards it.

Requests sent before `useBridgeAuth` reports `isReady` go out without credentials. Gate authenticated queries on it.

## Errors

`api.*` rejects with the axios error. The status and body are on `error.response`:

```tsx theme={null}
try {
  await api.post('/apps/blog/posts', draft);
} catch (error) {
  const status = (error as any)?.response?.status;
  if (status === 409) showConflict();
}
```

For AI endpoints, use [`aiCreditsExhausted(error)`](/sdk/ai-credits#handling-a-refusal) to recognize "out of credits".

## Raw instance

`apiClient` is the underlying axios instance, for interceptors or anything `api` does not cover:

```tsx theme={null}
import { apiClient } from '@cskn/sdk';

apiClient.interceptors.response.use(undefined, (error) => {
  report(error);
  return Promise.reject(error);
});
```


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