Response Variable Not Working

So I’ve read over the documentation on service calls and more specifically the part where it refers to response_variable for service calls. Attached is my current non working script. For context, I’m trying to take a prompt and use that prompt in the generate_image service. Then using the url that gets returned by that service I’m trying to pass said url through the response variable and then using a second service to write the url to an input_text to display it in a picture entity. The generate_image service runs fine, but I’m having trouble successfully passing the imageurl variable to the second service.

I already know it’s going to be something with my syntax or usage of the variable. Thanks for any help you may be able to give

alias: AI Generate
  - service: openai_conversation.generate_image
      size: "1024"
      config_entry: ###########################
      prompt: "{{states('input_text.ai_prompt')}}"
    response_variable: imageurl
  - service: input_text.set_value
      value: "{{ }}"
      entity_id: input_text.ai_prompt_return
mode: single
icon: mdi:brain

So my first mistake was using an input_text. The largest possible is 255 chars, and the urls that the service returns are 512. I should have read the docs on that. Now my issue is, I have no idea how to capture the response url from the service call.

I found this on the openai conversation HA documentation.

  - alias: "Update image when weather changes"
      - platform: state
        entity_id: weather.home
      - alias: "Ask OpenAI to generate an image"
        service: openai_conversation.generate_image
        response_variable: generated_image
          config_entry: f29e6b8696a15e107b4bd843de722249
          size: 512
          prompt: >-
            New York when the weather is {{ state("weather.home") }}"

      - alias: "Send out a manual event to update the image entity"
        event: new_weather_image
          url: '{{ generated_image.url }}'

  - trigger:
      alias: "Update image when a new weather image is generated"
      platform: event
      event_type: new_weather_image
      name: "AI generated image of New York"
      url: "{{ }}"

I’m confused because this doesn’t follow the format of any automation YAML that I’ve seen before, and when adding the template portion, that throws an error saying extra keys not allowed. So I don’t exactly know where this example configuration would go.

Did you ever get this figured out? I am having the same issue and don’t know how to replicate the example.

I did get this working for my example. It’s a little different than yours, but maybe it will help.

Here is the automation:

alias: Open AI Image Prompt Automation
description: ""
  - platform: state
      - input_text.open_ai_image_prompt
condition: []
  - service: openai_conversation.generate_image
      size: "512"
      config_entry: 145***redacted***96
      prompt: input_text.open_ai_image_prompt
    response_variable: generated_image_automation
  - event: new_openai_image
      url: "{{ generated_image_automation.url }}"
mode: single

After that I have a template sensor pick up the image. I am on mobile so I can’t easily copy that yaml, but I can get it later if it would be helpful.

Then I use a Lovelace card to display it.

type: picture
image_entity: image.ai_generated_image

I don’t use this for anything useful, I just wanted a quick way to play around with generating AI images from prompts.

So my interface looks like this, anytime the prompt changes you give it a few seconds to run and it displays the image:

There are more than 1000 posts on this forum most days, and the number of users who actively answer questions is a very small percentage of the total forum membership. These are often the same users who actively answer questions on other outlets like Facebook, Reddit, and Discord. It is very easy for a thread to fall low enough down the list that it gets missed. This is especially true when you are asking about a new feature on the day it is released; and, the integration in question requires an account with a third party…

It is the convention of the official docs to post YAML examples as-if they are being set up in configuration.yaml. It is also the unofficial/unenforced convention in this forum. That is what is going on in the example you posted.

Can you provide the yaml for your template sensor? I’m having trouble retrieving my image.