Web api chatgpt

in none drag and drop could someone guide me how to get chatgps API to work in web API if that’s possible

> import OpenAI from "openai";
> const openai = new OpenAI();
> const completion = await openai.chat.completions.create({
>     model: "gpt-4o",
>     store: true,
>     messages: [
>         {"role": "user", "content": "write a haiku about ai"}
>     ]
> });
> ```

what line of codes to what blocks.    eeehhhh
thanks

This post and the topic it’s in might help you get started:

i got it to work but had to do something like this as I could not get the objects to work lol


lol but it works

any idea how to do it with object blocks.


opens to null

What is the full response from the green block as text and which properties are you trying to get from it? If you can copy the response – I usually assign it to a Text Input so I can copy it – and paste it into Best JSON Viewer and JSON Beautifier Online as valid JSON, then you can see the path to specific properties.

I explain that here: API JSON Tutorial (Video)

thanks for replying
this is what i have “response X” is where the reply is

{
  "id": "chatcmpl-B6juxBD3GsZdCT8oVkQynTeaifMk8",
  "object": "chat.completion",
  "created": 1740946128,
  "model": "gpt-4o-2024-08-06",
  "choices": [
    {
      "index": 0,
      "message": {
        "role": "assistant",
        "content": "response X.",
        "refusal": null
      },
      "logprobs": null,
      "finish_reason": "stop"
    }
  ],
  "usage": {
    "prompt_tokens": 139,
    "completion_tokens": 25,
    "total_tokens": 164,
    "prompt_tokens_details": {
      "cached_tokens": 0,
      "audio_tokens": 0
    },
    "completion_tokens_details": {
      "reasoning_tokens": 0,
      "audio_tokens": 0,
      "accepted_prediction_tokens": 0,
      "rejected_prediction_tokens": 0
    }
  },
  "service_tier": "default",
  "system_fingerprint": "fp_eb9dce56a8"
}

The JSON text has to be formatted using the </> button in the forums toolbar so I went ahead and changed that for you. When I paste the response into the code beautify site and click on the “content” property that has the “response X.” value, the path is shown at the top:

Because Thunkable lists begin at 1, not 0, the property you need to get in Thunkable is:

choices[1].message.content

You can use that in the get property of object block but you’ll need to use the get object from JSON block with the green response block to convert the JSON response to an object.