Skip to main content
LlamaIndex is an open-source data framework for building applications with large language models (LLMs). TrueFoundry seamlessly integrates with LlamaIndex, allowing you to route all LLM requests through the TrueFoundry AI Gateway for enhanced security, routing, cost management, and more. This guide will walk you through connecting LlamaIndex with TrueFoundrry.
You should only use the OpenAILike and OpenAIEmbedding classes from LlamaIndex. These classes are designed for custom OpenAI-compatible endpoints, allowing you to use your TrueFoundry-specific model names directly. Using the standard OpenAI class will cause errors, as it validates model names against OpenAI’s public list.

Prerequisites

Before you begin, ensure you have the following:
  1. Authentication Token: A TrueFoundry API key. Follow the instructions in Generating Tokens to create one.
  2. Gateway Base URL: Your TrueFoundry AI Gateway Base URL ({GATEWAY_BASE_URL}). See Authentication for details.

Code Examples

The following examples demonstrate how to use LlamaIndex with TrueFoundry.

Chat Completion

This example shows how to perform chat completion.

Text Embedding

This example shows how to generate text embeddings.

FAQs

This error usually occurs when you’re using the OpenAI class from LlamaIndex instead of OpenAILike.
The OpenAI class strictly validates model names against OpenAI’s public list, so any custom or TrueFoundry-specific model name will result in this error.
To fix this, make sure you are using the OpenAILike class, which supports custom, OpenAI-compatible endpoints.