⚡ Live Interactive Code Sandbox: AI Dev Tool: Zod 466 compromised by
▶️ Run Code
💳 Unlock Source Code ($5)
📝 Editable Code Sandbox
```typescript // AI Dev Tool: Next.js Anthropic API Integration Wrapper // ================================================ // A production-ready API integration wrapper for Anthropic's AI models // using Next.js and Expo Monorepo Boilerplate import { NextApiRequest, NextApiResponse } from 'next'; import { z } from 'zod'; import axios from 'axios'; // Define the schema for the API request body const requestBodySchema = z.object({ prompt: z.string().min(1, 'Prompt is required'), model: z.string().min(1, 'Model is required'), }); // Define the API route for Anthropic's AI models const anthropicApiRoute = async (req: NextApiRequest, res: NextApiResponse) => { try { // Validate the request body using Zod const requestBody = requestBodySchema.parse(req.body); // Set the API endpoint and authentication headers const apiEndpoint = 'https://api.anthropic.com/v1/completions'; const apiKey = process.env.ANTHROPIC_API_KEY; const headers = { 'Content-Type': 'application/json', Authorization: `Bearer ${apiKey}`, }; // Set the API request payload const payload =
🖥️ Interactive Execution Terminal Console
⚡ Ready! Click ▶️ Run Code to execute code in browser terminal...