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.4.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.4.0
File Size Uploaded Provenance Actions
llama_index_llms_vercel_ai_gateway-0.4.0.tar.gz 4.4 kB Without provenance Details for llama_index_llms_vercel_ai_gateway-0.4.0.tar.gz

Built distribution (wheel)

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

Total release size: 9.3 kB

Release files / llama_index_llms_vercel_ai_gateway-0.4.0.tar.gz

Download URL llama_index_llms_vercel_ai_gateway-0.4.0.tar.gz
Size 4.4 kB
Tags Source
SHA-256 checksum
How to use checksums
0a01a2dffe6032ac484cc5349e4b196fb89ae944b5574442f639955f93d35444
BLAKE2b-256 checksum
How to use checksums
300b1045e0413044a288ca1aca1418fccf4366a27828709c096c8e2869ff6974
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.4.0-py3-none-any.whl

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

Security for llama-index-llms-vercel-ai-gateway 0.4.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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