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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| llama_index_llms_vercel_ai_gateway-0.3.1.tar.gz | 4.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| llama_index_llms_vercel_ai_gateway-0.3.1-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.1.tar.gz
| Download URL | llama_index_llms_vercel_ai_gateway-0.3.1.tar.gz |
|---|---|
| Size | 4.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa22b8716d32166aad64782e3f55133ea56aab31f86e318ac041372546d25d8a
|
|
BLAKE2b-256 checksum How to use checksums |
4aea914e9552f318afc8799aa1e830068941cd1060056d0f941a51087db30de2
|
| 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.1-py3-none-any.whl
| Download URL | llama_index_llms_vercel_ai_gateway-0.3.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1ca02c3bf6c39f3c3ed2077c606f3078af9e667d720710c51fb11d1b8c91caf7
|
|
BLAKE2b-256 checksum How to use checksums |
9ae637a78d5179f2e6da0c41a785a3baa574a325c1984baec13db04599c8e3e1
|
| 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}
|