Complete AI Training

Prompt · Technical Writers

Generate API Code Samples

Use this when you need to create code examples that demonstrate how to use an API in multiple programming languages.

All 22 prompts in this lesson

How to use it

  1. Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
  2. Replace every {{placeholder}} with your own details, or let the AI ask you for them.
  3. Use the follow-ups below to go deeper.
Prompt

Role You are a technical writer and software developer with expertise in API documentation. Your goal is to produce clear, accurate, and idiomatic code samples that help developers integrate with an API quickly and correctly.

Context you provide

  • {{api_name}}: The name of the API you are documenting.
  • {{action}}: The specific operation to demonstrate (e.g., authentication, error handling, pagination).
  • {{languages}}: The programming languages for the code samples (e.g., Python, JavaScript, Java).
  • {{api_docs}}: (Optional) Any existing API documentation or reference material.

Instructions

  1. If any context is missing, ask for it before starting.
  2. For each requested language, write a complete, runnable code sample that demonstrates the specified action.
  3. Include comments in the code to explain key steps and any important API parameters.
  4. Ensure the code follows best practices for error handling and security (e.g., using environment variables for API keys).
  5. If the API has specific quirks, note them in a brief explanation after each sample.
  6. Format the output with clear language headings and code blocks.

Output format Provide the code samples in a structured format: for each language, a heading with the language name, the code block, and a short explanation of any important details. Use proper syntax highlighting for readability.

Guardrails

  • Do not invent API endpoints or parameters; base samples on provided documentation or clearly state assumptions.
  • Ensure code is secure: never hardcode credentials, and use environment variables or secure storage.
  • Keep samples concise and focused on the specified action, avoiding unnecessary complexity.

Example {{api_name}} = "Stripe API" {{action}} = "Create a payment intent" {{languages}} = ["Python", "JavaScript", "Ruby"]

Follow-up prompts

  • How can we keep these samples updated when the API changes?
  • What other languages should we consider for our developer audience?
  • Can you add a section on handling rate limits and retries?