{"uid":"cap_CuW1cEj6ndN5yQNxYyk7u","slug":"meld402-ai-code-generation-7e79be1a","name":"meld402 AI Code Generation","description":"14 paid data endpoints for autonomous agents and developers. Covers crypto intelligence (token, chain, Solana, gas), markets (FX, market pulse), location (weather), and research (news, brief). Each route aggregates multiple public sources into one stable schema with a single USDC payment over x402 on Base.","url":"https://meld402.vercel.app/api/ai/code","method":"POST","headers":{},"bodySchema":{"type":"object","properties":{"model":{"enum":["gpt-4o","gpt-4o-mini","codellama","starcoder"],"type":"string","default":"gpt-4o","description":"Model to use"},"style":{"enum":["clean","functional","oop","minimal"],"type":"string","default":"clean","description":"Code style"},"prompt":{"type":"string","maxLength":5000,"minLength":1,"description":"Code generation prompt"},"language":{"type":"string","default":"typescript","description":"Programming language"},"framework":{"type":"string","description":"Framework/library (e.g., 'react', 'express', 'django')"},"include_tests":{"type":"boolean","default":true,"description":"Generate unit tests"},"include_explanation":{"type":"boolean","default":true,"description":"Include code explanation"}}},"responseSchema":{"type":"json","example":{"data":{"code":"import { createClient } from '@supabase/supabase-js';\n\nexport async function getUserPosts(userId: string) {\n  const supabase = createClient(\n    process.env.SUPABASE_URL!,\n    process.env.SUPABASE_ANON_KEY!\n  );\n\n  const { data, error } = await supabase\n    .from('posts')\n    .select('*')\n    .eq('user_id', userId)\n    .order('created_at', { ascending: false });\n\n  if (error) throw error;\n  return data;\n}","files":[{"path":"lib/posts.ts","content":"import { createClient } from '@supabase/supabase-js';\n\nexport async function getUserPosts(userId: string) {\n  const supabase = createClient(\n    process.env.SUPABASE_URL!,\n    process.env.SUPABASE_ANON_KEY!\n  );\n\n  const { data, error } = await supabase\n    .from('posts')\n    .select('*')\n    .eq('user_id', userId)\n    .order('created_at', { ascending: false });\n\n  if (error) throw error;\n  return data;\n}"}],"tests":"import { getUserPosts } from './posts';\n\njest.mock('@supabase/supabase-js', () => ({\n  createClient: () => ({\n    from: () => ({\n      select: () => ({\n        eq: () => ({\n          order: () => Promise.resolve({ data: [], error: null }),\n        }),\n      }),\n    }),\n}));\n\ntest('getUserPosts returns posts', async () => {\n  const posts = await getUserPosts('user-123');\n  expect(posts).toEqual([]);\n});","language":"typescript","framework":"supabase","model_used":"gpt-4o","explanation":"This function fetches all posts for a given user ID using Supabase client. It orders results by creation date descending.","tokens_used":{"total":1340,"prompt":450,"completion":890},"estimated_cost_usd":0.002},"meta":{"as_of":"2026-08-24T00:00:00.000Z","sources":["openai"],"degraded":[],"attribution":["AI generation by OpenAI (openai.com)"]}}},"example":null,"exampleRequest":null,"tags":["x402"],"displayCostAmount":"0.5","displayCostAsset":"USDC","priceDynamic":false,"priceHint":null,"priceStatus":"priced","priceSource":"probe","requiresHandshake":false,"reviewCount":0,"rating":{"score":"0.00","successRate":"0.00","reviews":0,"stars":null,"state":"unrated"},"availabilityStatus":"unknown","priceObserved":null,"sessionDeposit":null,"pricing":{"kind":"static","summary":"$0.5/call","primary":{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.5","per":"call","confidence":"exact"},"accepted":[{"kind":"static","protocol":"x402","network":"base","amountUsd":"0.5","per":"call","confidence":"exact"}]},"paymentMethods":[{"uid":"pm_70B8mQIJZY5NplcSAv-i7","protocol":"x402","methodType":"crypto","chain":"base","mode":"charge","costAmount":"0.5","costPer":"request","priority":0,"asset":"0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913","unit":"request","depositMicros":null,"planRef":null}],"brandName":null,"brandSlug":null,"brandBaseUrl":null,"brandDocsUrl":null,"whatItDoes":"Generates code in a specified language and style using AI models, optionally including unit tests and explanations, paid per request via x402/USDC.","exampleAgentPrompt":"Can you generate a clean TypeScript function using gpt-4o that fetches user posts from a Supabase table, include unit tests and a short explanation?","exampleUseCases":[{"title":"Scaffold React component with tests","prompt":"Write me a clean React component in TypeScript using gpt-4o that shows a paginated list of products — include Jest unit tests and an explanation of how it works."},{"title":"Generate Django REST API endpoint","prompt":"Generate a functional Python Django REST framework view for creating and listing blog posts, using gpt-4o-mini, and include unit tests."},{"title":"Minimal Express route with no tests","prompt":"Give me a minimal JavaScript Express.js route handler that validates a user login — no tests needed, just clean code, use the codellama model."}],"resultDescription":"Returns a JSON object containing the generated code string, an array of files with paths and contents, optional unit tests, a natural-language explanation, the language and framework used, which model was used, tokens consumed, and estimated cost. Metadata includes sources and attribution.","failureModes":["Invalid or missing prompt (minLength:1 violated) returns validation error","Unsupported model enum value returns 400","Prompt exceeds 5000 character limit returns error","Payment not fulfilled via x402 returns 402 Payment Required","Upstream AI provider downtime causes degraded or failed response","Unsupported language or framework may produce lower quality output"],"whenToPreferThis":"Choose this endpoint when you need AI-generated code with a stable, structured response schema and want to pay per call via USDC/x402 without managing API keys for OpenAI or code-specialist models. Ideal for agents that need to programmatically generate and parse code artifacts, file lists, and tests in a single request. Prefer over raw OpenAI API when you want a bundled, schema-consistent response including files, tests, and explanation together.","instructions":null,"reviewSummary":null,"reviewSummaryHighlights":null,"reviewSummaryConcerns":null,"reviewSummaryGeneratedAt":null,"activationCount":0,"lastUsedAt":null,"lastSuccessfullyRanAt":null,"lastHealthCheckAt":"2026-09-15T18:38:40.072Z","isFirstParty":false}