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

# LocalAI

> Integrate LocalAI-hosted models with Portkey for local LLM deployment with observability.

Portkey provides a robust gateway to facilitate the integration of your **locally hosted models through** [**LocalAI**](https://localai.io/).

## Integration Steps

**1. Expose your LocalAI Server**

Ensure your LocalAI API is externally accessible. If running on `http://localhost`, use a tool like `ngrok` to create a public URL.

```sh theme={"system"}
ngrok http 8080
```

**2. Add to Model Catalog**

1. Go to [**Model Catalog → Add Provider**](https://app.portkey.ai/model-catalog/providers)
2. Enable **"Local/Privately hosted provider"** toggle
3. Select **OpenAI** as the provider type (LocalAI follows OpenAI API schema)
4. Enter your LocalAI URL with `/v1` in **Custom Host**: `https://your-localai.ngrok-free.app/v1`
5. Name your provider (e.g., `my-localai`)

> [card] [Complete Setup Guide](https://docs.portkey.ai/docs/product/model-catalog.md)
>
> See all setup options

**3. Use in Your Application**

```python Python theme={"system"}
from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="@my-localai"
)

response = portkey.chat.completions.create(
    model="ggml-koala-7b-model-q4_0-r2.bin",
    messages=[{"role": "user", "content": "Hello!"}]
)

print(response.choices[0].message.content)
```

```javascript Node.js theme={"system"}
import Portkey from 'portkey-ai';

const portkey = new Portkey({
    apiKey: 'PORTKEY_API_KEY',
    provider: '@my-localai'
});

const response = await portkey.chat.completions.create({
    model: 'ggml-koala-7b-model-q4_0-r2.bin',
    messages: [{ role: 'user', content: 'Hello!' }]
});

console.log(response.choices[0].message.content);
```

**Or use custom host directly:**

```python Python theme={"system"}
from portkey_ai import Portkey

portkey = Portkey(
    api_key="PORTKEY_API_KEY",
    provider="openai",
    custom_host="https://your-localai.ngrok-free.app/v1"
)
```

```javascript Node.js theme={"system"}
import Portkey from 'portkey-ai';

const portkey = new Portkey({
    apiKey: 'PORTKEY_API_KEY',
    provider: 'openai',
    customHost: 'https://your-localai.ngrok-free.app/v1'
});
```

> [!NOTE]
>
> **Important:**
>
> * Don't forget to include the version identifier (`/v1`) in the Custom Host URL
> * Portkey supports all endpoints that adhere to the OpenAI specification

***

## LocalAI Endpoints Supported

| Endpoint | Resource |
| :- | :- |
| /chat/completions (Chat, Vision, Tools support) | [Doc](https://docs.portkey.ai/docs/api-reference/inference-api/chat.md) |
| /images/generations | [Doc](https://docs.portkey.ai/docs/api-reference/inference-api/images/create-image.md) |
| /embeddings | [Doc](https://docs.portkey.ai/docs/api-reference/inference-api/embeddings.md) |
| /audio/transcriptions | [Doc](https://docs.portkey.ai/docs/product/ai-gateway/multimodal-capabilities/speech-to-text.md) |

***

## Next Steps

> [card] [Gateway Configs](https://docs.portkey.ai/docs/product/ai-gateway.md)
>
> Add retries, timeouts, and fallbacks

> [card] [Observability](https://docs.portkey.ai/docs/product/observability.md)
>
> Monitor your LocalAI requests

> [card] [Custom Host Guide](https://docs.portkey.ai/docs/product/ai-gateway/universal-api.md#integrating-local-or-private-models)
>
> Learn more about custom host setup

> [card] [BYOLLM Guide](https://docs.portkey.ai/docs/integrations/llms/byollm.md)
>
> Complete guide for private LLMs

For complete SDK documentation:

> [card] [SDK Reference](https://docs.portkey.ai/docs/api-reference/sdk/list.md)
>
> Complete Portkey SDK documentation

***

> [card] [Portkey is now PRISMA AIRS AI Gateway. See it in action.](https://www.paloaltonetworks.in/ai-security/ai-gateway?utm_source=portkey\&utm_medium=referral\&utm_campaign=prisma_airs\&utm_content=docs_nav#contact)
>
> Contact Us


## Related topics

- [Overview](https://docs.portkey.ai/docs/integrations/llms.md)
- [Custom hosts](https://docs.portkey.ai/docs/product/ai-gateway/custom-hosts.md)
- [Anthropic Computer Use](https://docs.portkey.ai/docs/integrations/libraries/anthropic-computer-use.md)
- [Ollama](https://docs.portkey.ai/docs/integrations/llms/ollama.md)
- [Deepgram](https://docs.portkey.ai/docs/integrations/llms/deepgram.md)


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