LLM Prompts

API Integration Code Generator

Generates code snippets for integrating with APIs in a specified language.

The method

Use this prompt in ChatGPT or Gemini to generate code snippets for API integrations. Specify the target language and API endpoint details. Paste the generated code directly into your project, and adapt based on your needs. Aim to use for repetitive API integrations.

The prompts

Prompt 1
Generate a Python code snippet to fetch data from the OpenAI API's `/v1/models` endpoint. Include error handling and a loop to handle pagination if the API returns more than one page of results. The code should also include comments explaining each step. The response should be JSON formatted and easy to parse. Focus on handling rate limits gracefully and logging any errors that occur. Also, include a function to save the fetched data to a JSON file.
Prompt 2
I need a Javascript function that integrates with the Stripe API to create a new customer. The function should take the customer's name, email, and payment method ID as input. Include error handling for invalid input and API errors. The function should return the newly created customer ID or an error message. Use `async/await` for asynchronous operations. Also show how to handle Stripe webhooks to track customer signup events.
Prompt 3
Create a PHP script that integrates with the Twitter API (v2) to fetch the latest 10 tweets from a specific user's timeline. Use OAuth 2.0 for authentication. Include error handling for API rate limits and invalid user IDs. Display the tweets in a simple HTML format. The script should also include a form for users to enter the Twitter username and a button to trigger the API call. Make sure to sanitize the input to prevent cross-site scripting (XSS) vulnerabilities.