### Install Requesty Provider with AI SDK (pnpm, npm, yarn) Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Install the Requesty provider and the core AI SDK using your preferred package manager. ```bash # For pnpm pnpm add @requesty/ai-sdk ai # For npm npm install @requesty/ai-sdk ai # For yarn yarn add @requesty/ai-sdk ai ``` -------------------------------- ### Install AI SDK v5 and Requesty Provider Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Install the latest stable version of the AI SDK v5 and the Requesty provider using npm. ```bash npm install @requesty/ai-sdk ``` -------------------------------- ### Copy .env.example to .env Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Copy the example environment file to a new file named .env in the src/e2e directory. ```bash cp src/e2e/.env.example src/e2e/.env ``` -------------------------------- ### Install Requesty AI SDK Stable Versions Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Install the latest stable versions of the Requesty AI SDK and the core AI SDK. This is a prerequisite for using AI SDK v5 features. ```bash npm install @requesty/ai-sdk ai ``` -------------------------------- ### Set Requesty API Key Environment Variable Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Configure your Requesty API key as an environment variable for secure access. This example shows setup for Linux/Mac, Windows Command Prompt, and PowerShell. ```bash # Linux/Mac export REQUESTY_API_KEY=your_api_key_here # Windows Command Prompt set REQUESTY_API_KEY=your_api_key_here # Windows PowerShell $env:REQUESTY_API_KEY="your_api_key_here" ``` -------------------------------- ### Configure Model with Reasoning Effort and Extra Body Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md This example shows how to configure a specific chat model with a reasoning effort level and additional provider-specific options in the request body. ```typescript const model = requesty.chat('openai/gpt-4o', { reasoningEffort: 'high', extraBody: { requesty: { tags: ['premium-tier'], }, }, }); ``` -------------------------------- ### AI Agent with Multiple Tools and Requesty Tags Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Develop an AI agent for research tasks that can utilize multiple tools (web search, summarization, database saving). This example configures the agent with Requesty tags and a trace ID for research queries. ```typescript const researchAgent = async (query: string) => { const { text, toolResults } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: `Research and analyze: ${query}`, tools: { webSearch: searchTool, summarize: summarizeTool, saveToDatabase: saveTool, }, stopWhen: stepCountIs(10), providerOptions: { requesty: { tags: ['research', 'agent'], trace_id: `research_${Date.now()}`, }, }, }); return { analysis: text, sources: toolResults }; }; ``` -------------------------------- ### Customer Support Bot with Requesty Tags Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Create a customer support bot using Anthropic's Claude 3.5 Sonnet model. This example demonstrates how to tag requests with `customer-support` and include user-specific information. ```typescript const supportBot = async (userMessage: string, userId: string) => { return await generateText({ model: requesty.chat('anthropic/claude-3.5-sonnet'), prompt: `Customer: ${userMessage}`, providerOptions: { requesty: { tags: ['customer-support'], user_id: userId, extra: { department: 'support', priority: 'normal', }, }, }, }); }; ``` -------------------------------- ### Multi-Step Tool Calls with Stop Condition Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Implement multi-step processes using tools and define a stopping condition based on the number of tool call steps. This example limits the process to a maximum of 5 tool call steps. ```typescript import { generateText, stepCountIs } from 'ai'; const { text, steps } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: 'Research and summarize the latest AI developments', tools: { webSearch: searchTool, summarize: summarizeTool, }, stopWhen: stepCountIs(5), // Allow up to 5 tool call steps }); console.log('Final result:', text); console.log('Steps taken:', steps.length); ``` -------------------------------- ### Define Type-Safe Tool Results Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Create type definitions for tool calls and results to ensure type safety when handling responses from different tools. This example defines types for 'getWeather' and 'getNews' tools. ```typescript import { ToolCallUnion, ToolResultUnion } from 'ai'; const myTools = { getWeather: weatherTool, getNews: newsTool, }; type MyToolCall = ToolCallUnion; type MyToolResult = ToolResultUnion; // Use these types for type-safe tool handling ``` -------------------------------- ### Configure .env file Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Edit the .env file to add your Requesty API key and optionally set the Requesty API base URL. ```bash # Required: Your Requesty API key REQUESTY_API_KEY=your-api-key-here # Optional: Base URL for Requesty API (defaults to https://router.requesty.ai/v1) REQUESTY_BASE_URL=https://router.requesty.ai/v1 ``` -------------------------------- ### Run E2E tests with inline API key Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute E2E tests by providing the REQUESTY_API_KEY directly on the command line. ```bash REQUESTY_API_KEY='your-api-key-here' npm run test:e2e ``` -------------------------------- ### Create Requesty Provider with API Key Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Instantiate a Requesty provider using `createRequesty`, optionally providing your API key and a custom `baseURL`. The API key is optional if the `REQUESTY_API_KEY` environment variable is set. ```typescript import { createRequesty } from '@requesty/ai-sdk'; const requesty = createRequesty({ apiKey: process.env.REQUESTY_API_KEY, // optional if env var is set baseURL: 'https://router.requesty.ai/v1', // optional }); ``` -------------------------------- ### Run all E2E tests Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute all end-to-end integration tests using npm. This command runs tests with default models. ```bash npm run test:e2e ``` -------------------------------- ### Basic Text Generation with Requesty Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Generate text using a specified model from Requesty via the AI SDK. Ensure the `requesty` provider is imported. ```typescript import { requesty } from '@requesty/ai-sdk'; import { generateText } from 'ai'; const { text } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: 'Write a vegetarian lasagna recipe for 4 people.', }); ``` -------------------------------- ### Run pizza tests with custom models Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute pizza agent tests using custom models specified in the TEST_MODELS environment variable. Model IDs are provided in a comma-separated list. ```bash TEST_MODELS="openai/gpt-4o,anthropic/claude-3-5-sonnet-latest" npm run test:pizza ``` -------------------------------- ### Import Default Requesty Provider Instance Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Import the default `requesty` provider instance from the `@requesty/ai-sdk` package to use in your application. ```typescript import { requesty } from '@requesty/ai-sdk'; ``` -------------------------------- ### Configure Requesty Provider with Global Metadata Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Initialize the Requesty provider with global metadata that will be applied to all requests made through this instance. This includes tags and custom `extra` fields. ```typescript const requesty = createRequesty({ apiKey: process.env.REQUESTY_API_KEY, extraBody: { requesty: { tags: ['my-app'], extra: { environment: 'production', version: '1.0.0', }, }, }, }); ``` -------------------------------- ### Handle Tool Errors in Requesty AI SDK Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Demonstrates how to catch and identify specific errors that may occur during tool usage, such as missing tools, invalid arguments, or execution failures. Ensure the necessary error types are imported before use. ```typescript import { InvalidToolArgumentsError, NoSuchToolError, ToolExecutionError, } from 'ai'; try { const result = await generateText({ model: requesty.chat('openai/gpt-4o'), tools: { myTool }, prompt: 'Use the tool', }); } catch (error) { if (NoSuchToolError.isInstance(error)) { console.log('Tool not found'); } else if (InvalidToolArgumentsError.isInstance(error)) { console.log('Invalid tool arguments'); } else if (ToolExecutionError.isInstance(error)) { console.log('Tool execution failed'); } } ``` -------------------------------- ### Run pizza agent tests Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute the pizza agent tests, which are designed to verify model compatibility with a pizza ordering scenario. ```bash npm run test:pizza ``` -------------------------------- ### Streaming Text with Tools using Requesty Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Combine streaming text output with tool calling capabilities. This allows for real-time responses that can also invoke defined tools. ```typescript import { streamText } from 'ai'; const { textStream } = streamText({ model: requesty.chat('anthropic/claude-3.5-sonnet'), prompt: 'Get the weather and suggest clothing', tools: { getWeather: weatherTool, }, }); for await (const delta of textStream) { process.stdout.write(delta); } ``` -------------------------------- ### Tool Calling with Requesty Provider Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Implement tool calling functionality by defining tools with descriptions and input schemas using `zod`. The `generateText` function can then utilize these tools. ```typescript import { generateText, tool } from 'ai'; import { z } from 'zod'; const weatherTool = tool({ description: 'Get weather information', inputSchema: z.object({ location: z.string().describe('The city and country'), unit: z.enum(['celsius', 'fahrenheit']), }), execute: async ({ location, unit }) => { // Your weather API call here return `Weather in ${location}: 22°${unit === 'celsius' ? 'C' : 'F'}`; }, }); const { text } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: 'What is the weather like in Paris?', tools: { getWeather: weatherTool, }, }); ``` -------------------------------- ### Run E2E tests with multiple models Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Specify multiple models for E2E tests using a comma-separated list in the TEST_MODELS environment variable. Each model follows the format model_id:display_name. ```bash TEST_MODELS="openai/gpt-4o-mini:GPT-4o Mini,anthropic/claude-3-5-sonnet-latest:Claude 3.5 Sonnet" npm run test:e2e ``` -------------------------------- ### Content Generation Pipeline with Trace ID Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Generate a blog post on a given topic using OpenAI's GPT-4o model. This snippet includes Requesty-specific options like tags and a unique trace ID for tracking content generation requests. ```typescript const generateBlogPost = async (topic: string) => { const { text } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: `Write a blog post about: ${topic}`, providerOptions: { requesty: { tags: ['content-generation', 'blog'], trace_id: `blog_${Date.now()}`, extra: { content_type: 'blog_post', topic: topic, }, }, }, }); return text; }; ``` -------------------------------- ### Export API key environment variable Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Set the REQUESTY_API_KEY environment variable using the export command before running E2E tests. ```bash export REQUESTY_API_KEY='your-api-key-here' npm run test:e2e ``` -------------------------------- ### Run pizza agent tests in watch mode Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute the pizza agent tests in watch mode, automatically re-running them upon file changes. ```bash npm run test:pizza:watch ``` -------------------------------- ### Run E2E tests with a specific model Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Specify a single model to be used for all E2E tests using the TEST_MODELS environment variable. The format is model_id:display_name. ```bash TEST_MODELS="mistral/mistral-medium-latest:Mistral Medium" npm run test:e2e ``` -------------------------------- ### Enable Reasoning for Text Generation Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Use this snippet to enable reasoning tokens for models that support it, such as OpenAI o1, Anthropic, and DeepSeek. Configure the reasoning effort level from 'low' to 'max' or specify a budget string. ```typescript const { text, reasoning } = await generateText({ model: requesty.chat('openai/o1-preview', { reasoningEffort: 'medium', // 'low' | 'medium' | 'high' | 'max' }), prompt: 'Solve this complex math problem step by step...', }); console.log('Response:', text); console.log('Reasoning:', reasoning); // Step-by-step thinking ``` -------------------------------- ### Run E2E tests in watch mode Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/src/e2e/README.md Execute end-to-end integration tests in watch mode, which automatically re-runs tests when file changes are detected. ```bash npm run test:e2e:watch ``` -------------------------------- ### Update Streaming Protocol for AI SDK v5 Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Adapt your code for AI SDK v5's new streaming protocol. Instead of directly awaiting the stream, you now access `textStream` and iterate over it. ```typescript // Old (v4) const stream = await streamText(/* ... */); // New (v5) const { textStream } = streamText(/* ... */); for await (const delta of textStream) { // handle delta } ``` -------------------------------- ### Object Generation with Requesty Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Generate structured objects based on a provided schema using the `generateObject` function. The schema is defined using `zod` for validation. ```typescript import { generateObject } from 'ai'; import { z } from 'zod'; const { object } = await generateObject({ model: requesty.chat('openai/gpt-4o'), schema: z.object({ name: z.string(), age: z.number(), hobbies: z.array(z.string()), }), prompt: 'Generate a person profile. Return as JSON.', }); console.log(object); // { name: "John", age: 30, hobbies: ["reading", "hiking"] } ``` -------------------------------- ### Update Imports for AI SDK v5 Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Migrate from AI SDK v4 to v5 by updating import statements. AI SDK v5 uses different message types, requiring the use of `convertToModelMessages`. ```typescript // Old (v4) const messages = [{ role: 'user', content: 'Hello' }]; // New (v5) import { convertToModelMessages } from 'ai'; const messages = convertToModelMessages(uiMessages); ``` -------------------------------- ### Text Generation and Streaming with Requesty Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Perform non-streaming text generation or stream text responses using Requesty models. Supports specifying `maxOutputTokens` for non-streaming calls. ```typescript import { requesty } from '@requesty/ai-sdk'; // Streaming import { generateText, streamText } from 'ai'; // Non-streaming const { text } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: 'Explain quantum computing', maxOutputTokens: 500, }); const { textStream } = streamText({ model: requesty.chat('anthropic/claude-3.5-sonnet'), prompt: 'Write a story about AI', }); for await (const delta of textStream) { process.stdout.write(delta); } ``` -------------------------------- ### Add Custom Metadata to Requesty API Calls Source: https://github.com/requestyai/ai-sdk-requesty/blob/main/README.md Enhance API requests with custom metadata like tags, user IDs, and trace IDs for better analytics and tracking in the Requesty dashboard. The `extra` field allows for arbitrary key-value pairs. ```typescript import { generateText } from 'ai'; const { text } = await generateText({ model: requesty.chat('openai/gpt-4o'), prompt: 'Help with customer support', providerOptions: { requesty: { tags: ['customer-support', 'billing'], user_id: 'user_12345', trace_id: 'support_session_789', extra: { department: 'customer_success', priority: 'high', country: 'usa', }, }, }, }); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.