Beginner looking for API documentation as a prompt

Hey all, i am an absolute noob as a developer but i need several scripts in google sheets and other tools from time to time. Is there an easy documentation i can give Chat GPT about itselve how to write current API calls to assistants or competions or similar? I tried to print the documentation and use it as a prompt but it doesnt work.

I want to do it like this "Hey write me a script doing ThisTHatThis and call Assistant XYZ under API Key XYZ and put the result in Cell XYZ… Somehow open AI struggles all the time to write code for a self-referenced usage.

Thanks and sorry again, i cant write a single line of code by myselfe :slight_smile:

Rather than ChatGPT, fund your API account with credits, and then use the model GPT-4.1 to write your code.

https://platform.openai.com/playground/prompts?models=gpt-4.1

You might start with docs->quickstart on that page to see if using the API is completely out of your wheelhouse before making a purchase to fund the API calls.

Here’s Python that serves as a verbose example of what calling the RESTful API looks like, and parsing out the received response. You can have the AI follow the patterns there, but for the destination language, and simply to construct the single API function needed as input/output.

“Key” to this is keeping your API key secure. If it did work, putting your secrets equivalent to a bank password into a spreadsheet is NOT a good idea.

I tried this already. Maybe i am not clear enough sometimes i get really frustraded that it cant handle (for me) relatively simple requests, like:

"You are a professional programmer that helps an absolute noob to write scripts and code for their application to open AI APIs. Use the current documentation and functions from Open AI. I attached a quickstart guide.

Write a Google sheets App Script doing the following:

Check Cell H2, if it is empty, if this is the case
Send the prompt as text from Cell G2 to the Open AI assistant named below and post the answer to H2, Wait until you receive an answer.
Then go on with the next line until you reach end of google sheet file.

Log the progress. Check official references of code from Open AI assistant calls

Open AI Api Key: XXX
Assistend ID: XXX"

I am trying it now for almost 2 hours and just cant get a script running. Tried multiple models, prompts etc. Frustrating.

First: don’t use the gpt-4o model. It will go along with anything and produce fictional code.

You say you tried that, but I said to not use ChatGPT.

Let’s upgrade the AI:

Yes, Google Apps Script supports secure HTTPS calls with TLS 1.2 authentication, including requests requiring bearer tokens stored externally, such as an OpenAI API key.

Key considerations and capabilities:

  • HTTPS Requests:
    Google Apps Script uses the UrlFetchApp service to send HTTPS requests securely via TLS 1.2 by default. This ensures secure and encrypted communication between the script and external APIs.

  • Bearer Token Authentication:
    API keys, such as OpenAI’s, can be securely integrated using standard HTTP headers (Authorization: Bearer {API_KEY}).

  • Secure Storage of API Keys:
    For best security practice:

    • Store sensitive credentials using Apps Script’s built-in script property service (PropertiesService.getScriptProperties()), which securely stores values within Google’s infrastructure. Avoid hard-coding credentials directly in your scripts.
  • Example Implementation (Apps Script):

function callOpenAIFromCell() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const prompt = sheet.getRange('G2').getValue();
  
  const apiKey = PropertiesService.getScriptProperties().getProperty('OPENAI_API_KEY');

  const requestData = {
    "model": "gpt-4",
    "messages": [{"role": "user", "content": prompt}],
    "temperature": 0.1
  };

  const options = {
    "method": "post",
    "contentType": "application/json",
    "payload": JSON.stringify(requestData),
    "headers": {
      "Authorization": `Bearer ${apiKey}`
    },
    "muteHttpExceptions": true
  };

  const response = UrlFetchApp.fetch('https://api.openai.com/v1/chat/completions', options);
  const jsonResponse = JSON.parse(response.getContentText());

  const reply = jsonResponse.choices[0].message.content.trim();
  sheet.getRange('H2').setValue(reply);
}
  • Permissions and Security:
    The execution runs in Google’s secured, sandboxed infrastructure, isolating scripts from other scripts and environments.

  • Limits and Quotas:
    Be mindful of Google Apps Script quotas:

    • URL Fetch calls per day
    • Execution time limits per script invocation (typically 6 minutes for consumer accounts, 30 minutes for Workspace accounts)

In short, your requirement—securely making HTTPS requests with TLS 1.2 from Google Apps Script, storing API credentials securely, and interacting with APIs like OpenAI—is entirely achievable within Google’s existing infrastructure and capabilities.