Vercel AI SDK
Last updated 24 November 2026
@ktemia/ai-sdk gives an agent built with the Vercel AI SDK live travel prices: flight search, hotel search, and car rental search across 100+ providers. The model looks up the place, runs the search, and answers from real prices with each seller’s booking link.
Ktemia compares prices; it does not book. The traveller books on the seller’s site.
Source: Ktemiaa/ktemia-agent-toolkit on GitHub, MIT licensed.
Install
npm install @ktemia/ai-sdk ai zod
Create an API key at app.ktemia.com/api-keys. It is free, needs no card, and the Free plan includes 100 requests a month. Put it in your environment:
KTEMIA_API_KEY=your-key
Quick start
import { generateText, isStepCount } from 'ai';
import { ktemiaTools } from '@ktemia/ai-sdk';
const { text } = await generateText({
model: 'openai/gpt-5-mini',
tools: ktemiaTools(),
stopWhen: isStepCount(5),
prompt: 'What is the cheapest flight from Los Angeles to London on March 14?',
});
console.log(text);
A typical run takes three steps. The model calls ktemia_lookup to resolve “London” to LON, calls ktemia_search_flights, then writes the answer from the fares it got back.
The model string goes through the AI Gateway. To call a provider directly, pass its model instead, for example openai('gpt-5-mini') from @ai-sdk/openai or google('gemini-3.5-flash') from @ai-sdk/google.
Tools
ktemiaTools() returns all seven tools, sharing one client. The object keys are the names the model sees.
| Tool | Factory | Use it for | Cost |
|---|---|---|---|
ktemia_lookup |
lookup() |
Airport and city codes, airline codes, hotel and car location ids | 1 request |
ktemia_search_flights |
searchFlights() |
One-way, round trip, and multi-city fares | 2 requests, then 1 per page |
ktemia_search_hotels |
searchHotels() |
Stays, with stars, rating, price, and amenity filters | 2 requests, then 1 per page |
ktemia_search_cars |
searchCars() |
Rentals at a city or airport, with one-way drop-off | 2 requests, then 1 per page |
ktemia_get_details |
getDetails() |
Every price and booking link for one chosen result | 1 request |
ktemia_get_hotel_reviews |
hotelReviews() |
Guest reviews, by traveller type, month, or phrase | 1 request |
ktemia_key_status |
keyStatus() |
Plan and requests left this month | Free |
The tool descriptions are the same ones the Ktemia MCP server uses. They tell the model to resolve codes before searching, to ask for missing dates instead of guessing, and how to read the next page.
To give the model fewer tools, use the factories:
import { lookup, searchHotels, hotelReviews } from '@ktemia/ai-sdk';
const tools = {
ktemia_lookup: lookup(),
ktemia_search_hotels: searchHotels(),
ktemia_get_hotel_reviews: hotelReviews(),
};
Keep the ktemia_* names. The descriptions refer to each other by name, for example “use ktemia_lookup with kind=‘hotelLocation’ first”.
Chat in Next.js
Run the tools in a route handler and stream to the browser. The key stays on the server.
// app/api/chat/route.ts
import { convertToModelMessages, isStepCount, streamText, type UIMessage } from 'ai';
import { ktemiaTools } from '@ktemia/ai-sdk';
const tools = ktemiaTools();
export async function POST(req: Request) {
const { messages }: { messages: UIMessage[] } = await req.json();
const result = streamText({
model: 'openai/gpt-5-mini',
system: `You find live travel prices with the Ktemia tools. Today is ${new Date().toISOString().slice(0, 10)}. Ask for missing dates or places instead of guessing.`,
messages: await convertToModelMessages(messages),
tools,
stopWhen: isStepCount(8),
});
return result.toUIMessageStreamResponse();
}
On the client, useChat from @ai-sdk/react reads the stream. Put today’s date in the system prompt: models do not know it, and a search needs a future date.
A reusable agent
ToolLoopAgent packs the model, instructions, and tools into one object you can call from anywhere:
import { ToolLoopAgent, isStepCount } from 'ai';
import { hotelReviews, lookup, searchHotels } from '@ktemia/ai-sdk';
export const hotelAgent = new ToolLoopAgent({
model: 'openai/gpt-5-mini',
instructions:
'You compare hotels. Resolve the city with ktemia_lookup (kind hotelLocation), search, then read reviews for the top two before recommending one.',
tools: {
ktemia_lookup: lookup(),
ktemia_search_hotels: searchHotels(),
ktemia_get_hotel_reviews: hotelReviews(),
},
stopWhen: isStepCount(10),
});
const result = await hotelAgent.generate({
prompt: 'A quiet 4-star hotel in Lisbon, April 10 to 13, for two adults. Which one?',
});
Options
Every factory, and ktemiaTools(), takes the same options:
ktemiaTools({
apiKey: process.env.MY_KTEMIA_KEY, // default: KTEMIA_API_KEY
timeoutMs: 60_000, // per request; searches are the slow part
maxRetries: 2, // retries after a rate limit
});
To share a client with the rest of your app, pass it in:
import { Ktemia } from 'ktemia';
import { ktemiaTools } from '@ktemia/ai-sdk';
const client = new Ktemia();
const tools = ktemiaTools({ client });
Building the tools never fails, even without a key, so importing them at module scope is safe in a build. A missing key shows up on the first call, as an error the model can read.
Errors the model can act on
When Ktemia refuses a call, the tool returns the reason to the model instead of throwing, so the agent can recover:
{ "error": { "code": "INVALID_INPUT", "param": "departureDate", "retryable": false,
"message": "departureDate 2025-03-14 is in the past. Ask the user for a future date. Nothing was sent to Ktemia, so no quota was used." } }
| Case | What happens |
|---|---|
| Past date, city name in a code field, 40-night stay, return before departure | Rejected before sending. No quota spent. |
RATE_LIMIT_EXCEEDED |
Retried automatically after Retry-After, up to maxRetries. |
QUOTA_EXCEEDED |
Never retried. The month’s allowance is gone; ktemia_key_status shows the reset date. |
| No results | An empty page with a hint to try other dates, a nearby airport, or fewer filters. |
Errors that are not Ktemia’s, such as a bug in your code, are still thrown.
Paging and details
A search returns the first page and a nextToken. The model reads the next page by calling the same tool with only nextToken. Each page also carries its own token; ktemia_get_details takes that token and a result id and returns every price and booking link for that result. Tokens expire one hour after the search starts. See pagination.
Without the AI SDK
The client underneath is ktemia. It has no dependencies and works in any TypeScript or JavaScript project:
import { Ktemia } from 'ktemia';
const kt = new Ktemia();
const page = await kt.flights.search({ origin: 'LAX', destination: 'LON', departureDate: '2027-03-14' });
Related
- MCP server: the same tools for Cursor, Claude, Codex, and VS Code
- API reference: every endpoint, field, and error code
- Build an AI travel deal finder
- Flight search API
Questions
What is @ktemia/ai-sdk?
An npm package that gives a Vercel AI SDK agent seven travel tools. They search and compare flights, hotels, and rental cars across 100+ providers, look up airport codes and location ids, read hotel reviews, and return each provider's booking link.
Does it book flights or hotels?
No. Every tool is read-only. Ktemia compares prices and returns the provider's link, and the traveller books on the provider's site.
Which AI SDK versions and models does it support?
AI SDK 6 and 7, with zod 3.25 or 4. It works with any model that supports tool calls, through the AI Gateway or a provider package such as @ai-sdk/openai, @ai-sdk/anthropic, or @ai-sdk/google.
Is it free?
The package is MIT licensed. Calls use your Ktemia API key, and the Free plan includes 100 requests a month with no card. A search costs two requests, each further page or detail one, and ktemia_key_status is free.
Can I use it in the browser?
No. Run the tools on the server, in a route handler, server action, or script, so the API key never reaches the browser. Stream the answer to the client with streamText and useChat.
How is it different from the Ktemia MCP server?
Same seven tools, same descriptions, same quota. The MCP server is for clients like Cursor and Claude. @ktemia/ai-sdk is for agents you write in TypeScript, with no MCP connection to run.