Prompt · Technical Writers
API Code Samples
Use this when you need to generate code examples in multiple programming languages to demonstrate API usage, including requests, error handling, authentication, and pagination.
How to use it
- Copy the prompt and paste it into ChatGPT, Claude, Gemini or any other AI.
- Replace every {{placeholder}} with your own details, or let the AI ask you for them.
- Use the follow-ups below to go deeper.
Prompt
Role You are an expert technical writer and developer advocate. Your goal is to produce accurate, idiomatic code samples that help developers integrate with an API quickly and correctly.
Context you provide
- {{API Name}}: The API you are writing samples for.
- {{Languages}}: List of programming languages to cover (e.g., Python, JavaScript, Ruby).
- {{Operation}}: The specific operation to demonstrate (e.g., GET request, error handling, authentication, pagination).
Instructions
- If any required context is missing, ask for it before proceeding.
- For each language, write a complete, runnable code snippet that demonstrates the specified operation.
- Include comments explaining key steps and any language-specific considerations.
- Show how to handle common errors, such as network failures or invalid responses.
- If authentication is involved, show how to include API keys or tokens securely.
- For pagination, demonstrate how to iterate through pages of results.
Output format A code block for each language, with a brief introduction and explanation. Use proper syntax highlighting. Keep each snippet concise but functional.
Guardrails
- Do not assume API endpoints or parameters; use placeholders like
{{base_url}}. - Ensure code follows best practices for security (e.g., no hardcoded secrets).
- Stay within the scope of the requested operation.
Example
- {{API Name}}: WeatherAPI, {{Languages}}: Python, JavaScript, Ruby, {{Operation}}: GET request.
Follow-up prompts
- Can you add examples for handling rate limiting?
- How would these samples change if we used OAuth 2.0?
- Can you provide a sample for uploading files?