Skip to main content

LlamaIndex Llms Integration: Vercel AI Gateway

Installation

To install the required packages, run:

%pip install llama-index-llms-vercel-ai-gateway
!pip install llama-index

Setup

Initialize Vercel AI Gateway

You need to set either the environment variable VERCEL_AI_GATEWAY_API_KEY, VERCEL_OIDC_TOKEN, or pass your API key directly in the class constructor. Replace <your-api-key> with your actual API key:

from llama_index.llms.vercel_ai_gateway import VercelAIGateway
from llama_index.core.llms import ChatMessage

llm = VercelAIGateway(
    api_key="<your-api-key>",
    max_tokens=200000,
    context_window=64000,
    model="anthropic/claude-4-sonnet",
)

Generate Chat Responses

You can generate a chat response by sending a list of ChatMessage instances:

message = ChatMessage(role="user", content="Tell me a joke")
resp = llm.chat([message])
print(resp)

Streaming Responses

To stream responses, use the stream_chat method:

message = ChatMessage(role="user", content="Tell me a story in 250 words")
resp = llm.stream_chat([message])
for r in resp:
    print(r.delta, end="")

Complete with Prompt

You can also generate completions with a prompt using the complete method:

resp = llm.complete("Tell me a joke")
print(resp)

Streaming Completion

To stream completions, use the stream_complete method:

resp = llm.stream_complete("Tell me a story in 250 words")
for r in resp:
    print(r.delta, end="")

Model Configuration

To use a specific model, you can specify it during initialization. For example, to use Anthropic's Claude 3 Sonnet model, you can set it like this:

llm = VercelAIGateway(model="anthropic/claude-4-sonnet")
resp = llm.complete("Write a story about a dragon who can code in Rust")
print(resp)

LLM Implementation example

https://docs.llamaindex.ai/en/stable/examples/llm/vercel-ai-gateway/

Metadata

Release files for llama-index-llms-vercel-ai-gateway 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for llama-index-llms-vercel-ai-gateway 0.3.0
File Size Uploaded
llama_index_llms_vercel_ai_gateway-0.3.0.tar.gz 4.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-llms-vercel-ai-gateway 0.3.0
File Interpreter ABI Platform
llama_index_llms_vercel_ai_gateway-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / llama_index_llms_vercel_ai_gateway-0.3.0.tar.gz

Download URL llama_index_llms_vercel_ai_gateway-0.3.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
3ecb7727f18f7ba6eb623a2049e92002e108067f94f99663a63e2bfb6c8813d7
BLAKE2b-256 checksum
How to use checksums
4e0721019057f1a2d35dbd5003c09a325cfb1135962698e099912cc2006a10d0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_llms_vercel_ai_gateway-0.3.0-py3-none-any.whl

Download URL llama_index_llms_vercel_ai_gateway-0.3.0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
61fcfa28a04611051f5f82644277a03a4149ac25d529d5131fb06ab981441199
BLAKE2b-256 checksum
How to use checksums
426fb8e0a57d45f7f80d575dd8f79b0f8926e09a1ae10840f5280d9cf590fe15
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release history Release notifications | RSS feed

0.3.1

2 release files

This release

0.3.0 This release

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page