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

# AI SDKs

> Installation, initialisation, and method coverage for the @livepeer/ai JavaScript SDK and livepeer-ai Python SDK.

export const TableCell = ({children, align = "left", header = false, style = {}, className = "", ...rest}) => {
  const Component = header ? "th" : "td";
  return <Component className={className} style={{
    padding: "0.75rem 1rem",
    textAlign: align,
    border: header ? "none" : "1px solid var(--lp-color-border-default)",
    ...style
  }} {...rest}>
      {children}
    </Component>;
};

export const TableRow = ({children, header = false, hover = false, style = {}, className = "", ...rest}) => {
  const rowId = `table-row-${Math.random().toString(36).substr(2, 9)}`;
  return <>
      {hover && <style>{`
          #${rowId}:hover {
            background-color: var(--lp-color-bg-card);
          }
        `}</style>}
      <tr id={rowId} className={className} style={{
    ...header && ({
      backgroundColor: "var(--lp-color-accent-strong)",
      color: "var(--lp-color-on-accent)",
      fontWeight: "bold"
    }),
    ...style
  }} {...rest}>
        {children}
      </tr>
    </>;
};

export const StyledTable = ({children, variant = "default", style = {}, className = "", ...rest}) => {
  const wrapperVariants = {
    default: {
      border: "1px solid var(--lp-color-border-default)",
      backgroundColor: "var(--lp-color-bg-card)",
      overflow: "hidden"
    },
    bordered: {
      border: "2px solid var(--lp-color-accent)",
      backgroundColor: "var(--lp-color-bg-page)",
      overflow: "hidden"
    },
    minimal: {
      border: "none",
      backgroundColor: "transparent",
      overflow: "visible"
    }
  };
  return <div data-docs-styled-table-shell className={className} style={{
    width: "100%",
    padding: 0,
    margin: 0,
    ...wrapperVariants[variant],
    ...style
  }} {...rest}>
      <table data-docs-styled-table style={{
    width: "100%",
    borderCollapse: "collapse",
    borderSpacing: 0,
    margin: 0,
    backgroundColor: "transparent"
  }}>
        {children}
      </table>
    </div>;
};

export const CenteredContainer = ({children, maxWidth = "800px", padding = "0", preset = "default", width = "", minWidth = "", marginRight = "", marginBottom = "", textAlign = "", style = {}, className = "", ...rest}) => {
  const presets = {
    default: {},
    fitContent: {
      width: "fit-content",
      minWidth: "fit-content"
    },
    readable70: {
      width: "70%",
      minWidth: "fit-content"
    },
    readable80: {
      width: "80%",
      minWidth: "fit-content"
    },
    readable90: {
      width: "90%"
    },
    wide900: {
      maxWidth: "900px"
    }
  };
  const presetStyle = presets[preset] || presets.default;
  return <div className={className} style={{
    maxWidth: presetStyle.maxWidth || maxWidth,
    margin: "0 auto",
    padding: padding,
    ...presetStyle.width ? {
      width: presetStyle.width
    } : {},
    ...presetStyle.minWidth ? {
      minWidth: presetStyle.minWidth
    } : {},
    ...width ? {
      width
    } : {},
    ...minWidth ? {
      minWidth
    } : {},
    ...marginRight ? {
      marginRight
    } : {},
    ...marginBottom ? {
      marginBottom
    } : {},
    ...textAlign ? {
      textAlign
    } : {},
    ...style
  }} {...rest}>
      {children}
    </div>;
};

export const LinkArrow = ({href, label, description, newline = true, borderColor, className = '', style = {}, ...rest}) => {
  const linkArrowStyle = {
    display: 'inline-flex',
    alignItems: 'center',
    justifyContent: 'center',
    gap: "var(--lp-spacing-1)",
    width: 'fit-content',
    ...borderColor && ({
      borderColor
    })
  };
  return <span className={className} style={style} {...rest}>
      {newline && <br />}
      <span style={linkArrowStyle}>
        <a href={href} target="_blank" rel="noopener noreferrer">
          {label}
        </a>
        <Icon icon="arrow-up-right" size={14} color="var(--lp-color-accent)" />
      </span>
      {description && description}
      {description && <div style={{
    height: "var(--lp-spacing-3)"
  }} />}
    </span>;
};

<CenteredContainer preset="readable90">
  <Tip>Both SDKs are generated from the ai-runner OpenAPI specification and mirror the same pipeline endpoint surface. Pin to a specific version; both are in alpha and may have breaking changes between releases.</Tip>
</CenteredContainer>

***

Two official SDKs wrap the Livepeer AI Gateway REST API: `@livepeer/ai` for JavaScript and TypeScript, and `livepeer-ai` for Python. Both are generated programmatically from the `ai-runner` OpenAPI specification and cover the same set of pipeline endpoints.

<Note>
  `@livepeer/ai` is in alpha. Pin your dependency to a specific version to avoid unintended breaking changes on update.
</Note>

<CustomDivider />

## @livepeer/ai

The JavaScript SDK supports Node.js, Bun, and browser runtimes. It requires `zod` as a peer dependency.

**Installation:**

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
npm install @livepeer/ai zod
# or
yarn add @livepeer/ai zod
# or
pnpm add @livepeer/ai zod
```

**Initialisation:**

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { Livepeer } from '@livepeer/ai';

const livepeer = new Livepeer({
  httpBearer: '<YOUR_GATEWAY_TOKEN>',
});
```

For development against the public community Gateway at `dream-gateway.livepeer.cloud`, no bearer token is required. Pass an empty string or omit the field for unauthenticated access.

**Text-to-image example:**

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { Livepeer } from '@livepeer/ai';

const livepeer = new Livepeer({
  httpBearer: '',
});

const result = await livepeer.generate.textToImage({
  modelId: 'ByteDance/SDXL-Lightning',
  prompt: 'A fox sitting on a moonlit rooftop',
  width: 1024,
  height: 1024,
});

console.log(result.imageResponse?.images?.[0]?.url);
```

**Error handling:**

The SDK throws typed errors. `SDKValidationError` indicates the response did not match the expected schema. `HTTPError` covers Gateway-level HTTP errors.

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import { Livepeer } from '@livepeer/ai';
import { HTTPError, SDKValidationError } from '@livepeer/ai/models/errors';

try {
  const result = await livepeer.generate.textToImage({ ... });
} catch (err) {
  if (err instanceof SDKValidationError) {
    console.error(err.pretty());
  } else if (err instanceof HTTPError) {
    console.error(err.statusCode, err.body);
  }
}
```

**Custom Gateway URL:**

```typescript theme={"theme":{"light":"github-light","dark":"dark-plus"}}
const livepeer = new Livepeer({
  serverURL: 'https://your-gateway.example.com',
  httpBearer: '<YOUR_TOKEN>',
});
```

<CustomDivider />

## Livepeer AI

The Python SDK supports Python 3.8 and later.

**Installation:**

```bash theme={"theme":{"light":"github-light","dark":"dark-plus"}}
pip install livepeer-ai
```

**Initialisation:**

```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
from livepeer_ai import Livepeer

client = Livepeer(
    http_bearer='<YOUR_GATEWAY_TOKEN>',
)
```

**Text-to-image example:**

```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
from livepeer_ai import Livepeer
from livepeer_ai.models import components

client = Livepeer(http_bearer='')

result = client.generate.text_to_image(
    components.TextToImageParams(
        model_id='ByteDance/SDXL-Lightning',
        prompt='A fox sitting on a moonlit rooftop',
        width=1024,
        height=1024,
    )
)

print(result.image_response.images[0].url)
```

**Async usage:**

The Python SDK exposes an async client for use in async applications:

```python theme={"theme":{"light":"github-light","dark":"dark-plus"}}
import asyncio
from livepeer_ai import AsyncLivepeer
from livepeer_ai.models import components

async def main():
    client = AsyncLivepeer(http_bearer='')
    result = await client.generate.text_to_image(
        components.TextToImageParams(
            model_id='ByteDance/SDXL-Lightning',
            prompt='A fox sitting on a moonlit rooftop',
        )
    )
    print(result.image_response.images[0].url)

asyncio.run(main())
```

<CustomDivider />

## Pipeline Method Reference

Both SDKs expose a `generate` namespace containing one method per pipeline type. The method names use camelCase in JavaScript and snake\_case in Python.

<StyledTable variant="bordered">
  <thead>
    <TableRow header>
      <TableCell header>Pipeline</TableCell>
      <TableCell header>JS method</TableCell>
      <TableCell header>Python method</TableCell>
    </TableRow>
  </thead>

  <tbody>
    <TableRow>
      <TableCell>`text-to-image`</TableCell>
      <TableCell>`generate.textToImage()`</TableCell>
      <TableCell>`generate.text_to_image()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`image-to-image`</TableCell>
      <TableCell>`generate.imageToImage()`</TableCell>
      <TableCell>`generate.image_to_image()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`image-to-video`</TableCell>
      <TableCell>`generate.imageToVideo()`</TableCell>
      <TableCell>`generate.image_to_video()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`image-to-text`</TableCell>
      <TableCell>`generate.imageToText()`</TableCell>
      <TableCell>`generate.image_to_text()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`audio-to-text`</TableCell>
      <TableCell>`generate.audioToText()`</TableCell>
      <TableCell>`generate.audio_to_text()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`text-to-speech`</TableCell>
      <TableCell>`generate.textToSpeech()`</TableCell>
      <TableCell>`generate.text_to_speech()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`upscale`</TableCell>
      <TableCell>`generate.upscale()`</TableCell>
      <TableCell>`generate.upscale()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`segment-anything-2`</TableCell>
      <TableCell>`generate.segmentAnything2()`</TableCell>
      <TableCell>`generate.segment_anything2()`</TableCell>
    </TableRow>

    <TableRow>
      <TableCell>`llm`</TableCell>
      <TableCell>`generate.llm()`</TableCell>
      <TableCell>`generate.llm()`</TableCell>
    </TableRow>
  </tbody>
</StyledTable>

<CustomDivider />

## Repositories and Versioning

Both SDKs are generated from the `ai-runner` OpenAPI spec and published independently:

* JavaScript: `github.com/livepeer/livepeer-ai-js`: published to npm as `@livepeer/ai`
* Python: `github.com/livepeer/livepeer-ai-python`: published to PyPI as `livepeer-ai`

The deprecated `livepeer/livepeer-ai-sdks` repository contains older auto-generated SDKs and is no longer maintained.

<CustomDivider />

## Related Pages

The AI SDKs wrap the Gateway inference endpoints. For the full endpoint reference with request schemas and curl examples, see [AI pipelines](/v2/developers/build/ai-and-agents/ai-pipelines).

<CardGroup cols={2}>
  <Card title="AI Pipelines" icon="cpu" href="/v2/developers/build/ai-and-agents/ai-pipelines" arrow horizontal>
    Endpoint shapes and curl examples for all nine pipeline types.
  </Card>

  <Card title="AI Jobs Quickstart" icon="bolt" href="/v2/developers/build/ai-and-agents/ai-jobs-direct-quickstart" arrow horizontal>
    First API call in under ten minutes using curl or the SDK.
  </Card>

  <Card title="AI API Reference" icon="book" href="/v2/developers/resources/reference/apis" arrow horizontal>
    Full OpenAPI-derived schema reference for all pipeline endpoints.
  </Card>

  <Card title="Overview" icon="grid" href="/v2/developers/build/ai-and-agents/overview" arrow horizontal>
    Pipeline categories and access model overview.
  </Card>
</CardGroup>
