The Mental Model
The Session Musician with Sheet Music.
Without docs, the AI improvises—it guesses endpoints, invents parameters, hallucinates entire APIs. With docs, it plays the exact notes. Every function call is real.
The AI guesses based on training data. Endpoints may not exist.
The AI reads the real API spec. Every call is accurate.
No hallucinated endpoints. No made-up parameters. Just working code.
Give the AI the sheet music. It will play perfectly.
// AI guesses the API...
const res = await fetch(
'/api/stripe/create-payment'
);
⚠ Endpoint doesn't exist
⚠ Wrong parameter names
⚠ Missing required fields
// AI reads the real API spec...
const session = await stripe
.checkout.sessions.create({
line_items: [{ price, quantity }],
mode: 'payment',
success_url: '...',
});
✓ Real endpoint, real params
The Doc Injection Workflow
Copy the Docs
Go to the official documentation. Find the specific page for the feature you need. Select the relevant section—not the entire docs site, just the part that matters.
// Stripe Checkout Sessions
POST /v1/checkout/sessions
Parameters:
line_items array, required
mode 'payment' | 'subscription'
success_url string, required
cancel_url string
↑ Copy this section
Paste into Context
Include the docs in your AI prompt using clear delimiters. The AI needs to know where the documentation starts and ends so it can distinguish your instructions from the reference material.
Here is the official documentation
for Stripe Checkout:
```
[PASTED DOCS GO HERE]
```
↑ Clear delimiters
Ask Specifically
Tell the AI exactly what to build using those docs. Don't say "integrate Stripe." Say "Build a checkout button that creates a Stripe Checkout Session using the API shown in the docs above."
Based on this documentation, build
a checkout flow that:
1. Creates a Checkout Session
2. Redirects user to Stripe
3. Handles success/cancel URLs
Use Next.js API routes.
Handle errors properly.
↑ Specific instructions
Real-World Examples
Stripe
Checkout Session
// Doc snippet you'd paste:
POST /v1/checkout/sessions
line_items: [{ price, qty }]
mode: 'payment'
success_url: string
Your prompt:
"Build a checkout button that creates a Stripe session and redirects the user."
OpenAI
Chat Completion
// Doc snippet you'd paste:
POST /v1/chat/completions
model: 'gpt-4o'
messages: [{ role, content }]
temperature: 0-2
Your prompt:
"Build an API route that sends a user message to OpenAI and streams the response."
Resend
Transactional Email
// Doc snippet you'd paste:
POST /emails
from: 'you@domain.com'
to: ['user@email.com']
subject, html
Your prompt:
"Build a transactional email sender that sends a welcome email after signup."
The Prompt Template
The Universal Doc Injection Prompt
Use this template every time you need to integrate with an external service. Replace the brackets with your specifics.
Here is the official documentation for [SERVICE]:
```
[PASTE DOCS HERE]
```
Based on this documentation, build [SPECIFIC FEATURE].
Use [FRAMEWORK / LANGUAGE].
Handle errors properly.
// Optional additions:
Include TypeScript types.
Add environment variable validation.
Follow the project structure I'm using.
Pro tip: The more specific your [SPECIFIC FEATURE] description, the better the output. "Build Stripe integration" is vague. "Build a checkout button that creates a Stripe Checkout Session with a single line item and redirects to a success page" is precise.
Common Patterns
✗ Integration Traps
"Integrate Stripe for me"
No docs provided. The AI guesses endpoints from memory—which may be outdated or wrong.
Hallucinated endpoints
/api/stripe/create-payment doesn't exist. The real endpoint is stripe.checkout.sessions.create().
Pasting the entire docs site
Too much context overwhelms the AI. Paste only the specific section for your feature.
Trusting without verifying
Even with docs, always test the generated code against the real API.
✓ The Clean Integration
Paste the official docs first
Always include the real API reference before asking the AI to build anything.
Be specific about what to build
"Create a POST /api/checkout route using stripe.checkout.sessions.create()" — precise and actionable.
Ask for error handling
Always request try/catch blocks, input validation, and meaningful error responses.
Test against the real API
Use test mode / sandbox keys. Hit the endpoint. Confirm the response matches docs.
The Exercises
Inject docs. Build integrations.
The Stripe Injection
Checkout Flow
- →Copy the Stripe Checkout Session docs
- →Paste into AI with the template prompt
- →Ask it to build a checkout button
The OpenAI Injection
Chat Endpoint
- →Copy the OpenAI Chat Completion docs
- →Paste into AI context with delimiters
- →Build a simple chat API endpoint
The Email Injection
Transactional Email
- →Copy the Resend API docs for sending emails
- →Paste into AI with clear delimiters
- →Build a transactional email sender
📋 Quick Reference Cheatsheet
Inject Docs
```[paste docs here]```Be Specific
"Build [feature] using [framework]"Always Add
"Handle errors properly."