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

# Kernel SDK

> Point the Kernel SDK at querying.ai Browser, then create a browser, connect Playwright over CDP, open the live view and delete the browser.

The Kernel Python and TypeScript SDKs and the Kernel CLI work with querying.ai Browser. Set the SDK's base URL to `https://api.querying.ai/browser` and its API key to your querying.ai `vt_` key. Features, limits, concurrency and prices are on the [Browser API](https://docs.querying.ai/browser/overview.md) page.

## 1. Set your API key

```bash theme={"theme":"css-variables"}
export QUERYING_API_KEY="vt_..."
```

## 2. Create a browser and drive it

```python Python theme={"theme":"css-variables"}
import os

from kernel import Kernel
from playwright.sync_api import sync_playwright

kernel = Kernel(
    api_key=os.environ["QUERYING_API_KEY"],
    base_url="https://api.querying.ai/browser",
)

browser = kernel.browsers.create(stealth=True, headless=True)
print("Live view:", browser.browser_live_view_url)

try:
    with sync_playwright() as p:
        cdp = p.chromium.connect_over_cdp(browser.cdp_ws_url)
        context = cdp.contexts[0] if cdp.contexts else cdp.new_context()
        page = context.pages[0] if context.pages else context.new_page()
        page.goto("https://example.com")
        print(page.title())
        cdp.close()
finally:
    kernel.browsers.delete_by_id(browser.session_id)
```

```typescript TypeScript theme={"theme":"css-variables"}
import Kernel from "@onkernel/sdk";
import { chromium } from "playwright-core";

const kernel = new Kernel({
  apiKey: process.env.QUERYING_API_KEY,
  baseURL: "https://api.querying.ai/browser",
});

const browser = await kernel.browsers.create({ stealth: true, headless: true });
console.log("Live view:", browser.browser_live_view_url);

try {
  const cdp = await chromium.connectOverCDP(browser.cdp_ws_url);
  const context = cdp.contexts()[0] ?? (await cdp.newContext());
  const page = context.pages()[0] ?? (await context.newPage());
  await page.goto("https://example.com");
  console.log(await page.title());
  await cdp.close();
} finally {
  await kernel.browsers.deleteByID(browser.session_id);
}
```

* `stealth: true` gives the browser a fresh fingerprint, a residential exit and automatic captcha solving. Traffic through the residential exit is billed per GB. See [Billing](https://docs.querying.ai/browser/overview.md#billing).
* `browser_live_view_url` opens the live view in any browser tab. `kernel.browsers.live_view.create(session_id)` issues a read-only (default) or control URL; `scope` and `ttl_seconds` set the access and an optional expiry.
* `cdp_ws_url` carries a token for this session, so Playwright connects with no API key. Puppeteer connects with `puppeteer.connect({ browserWSEndpoint: browser.cdp_ws_url })`.
* Deleting the browser stops its charges. A browser that has no client connected for `timeout_seconds` (60 by default) ends on its own.

## 3. Send an HTTP request through the browser

`browsers.curl` sends a request through the browser's network and returns the status and body:

```python theme={"theme":"css-variables"}
response = kernel.browsers.curl(browser.session_id, url="https://example.com/", method="GET")
print(response.status, response.body[:80])
```

`browsers.request`, `browsers.stream` and `browsers.fetch` are unavailable at this base URL. Use `browsers.curl`.

## 4. Keep a site signed in with Managed Auth

Store the site's login as a credential and link it to a profile with a connection. `login()` signs the profile in. The connection then checks the login every `health_check_interval` seconds (3600 by default, at least 300) and signs in again with the credential when the site has signed the profile out.

```python Python theme={"theme":"css-variables"}
import os
import time

kernel.credentials.create(
    name="shop-login",
    domain="shop.example.com",
    values={"username": "user@example.com", "password": os.environ["SHOP_PASSWORD"]},
)
auth = kernel.auth.connections.create(
    domain="shop.example.com",
    profile_name="shop-user-1",
    credential={"name": "shop-login"},
    login_url="https://shop.example.com/login",
)
kernel.auth.connections.login(auth.id)
while (auth := kernel.auth.connections.retrieve(auth.id)).flow_status == "IN_PROGRESS":
    time.sleep(2)
print(auth.status)  # AUTHENTICATED

browser = kernel.browsers.create(profile={"name": "shop-user-1"}, stealth=True)
```

```typescript TypeScript theme={"theme":"css-variables"}
await kernel.credentials.create({
  name: "shop-login",
  domain: "shop.example.com",
  values: { username: "user@example.com", password: process.env.SHOP_PASSWORD! },
});
let auth = await kernel.auth.connections.create({
  domain: "shop.example.com",
  profile_name: "shop-user-1",
  credential: { name: "shop-login" },
  login_url: "https://shop.example.com/login",
});
await kernel.auth.connections.login(auth.id);
while ((auth = await kernel.auth.connections.retrieve(auth.id)).flow_status === "IN_PROGRESS") {
  await new Promise((resolve) => setTimeout(resolve, 2000));
}
console.log(auth.status); // AUTHENTICATED

const browser = await kernel.browsers.create({ profile: { name: "shop-user-1" }, stealth: true });
```

* A browser that opens the profile starts signed in to the site.
* A login that needs a person, such as an SMS or email code, an account choice or an approval, pauses at `hosted_url`, where the person finishes it in the live view. When an automatic re-login needs a person, the connection moves to `NEEDS_AUTH` with an `error_code` such as `sms_code_required`, and `can_reauth_reason` names what the next login needs. With a `totp_secret` on the credential, re-logins enter authenticator codes themselves.
* `auth.connections.timeline(id)` lists logins, re-logins and health checks. Call `login()` right before work that needs the session: while the profile is signed in, it reaches `SUCCESS` at once.
* Health checks and re-logins run in headful browsers billed as browser time. Once a check finds the profile signed out, a connection that cannot sign in again on its own is not checked until the next `login()`. See [Billing](https://docs.querying.ai/browser/overview.md#billing).

## Kernel CLI

Point the CLI at the same base URL:

```bash theme={"theme":"css-variables"}
export KERNEL_BASE_URL="https://api.querying.ai/browser"
export KERNEL_API_KEY="$QUERYING_API_KEY"
kernel browsers create -H
```

Next: [Browserbase SDK](https://docs.querying.ai/browser/browserbase-sdk.md), [Credits and limits](https://docs.querying.ai/concepts/credits-and-limits.md).


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