<turbo-stream action="append" target="posts_list"><template>    <div class="postbit" id="366814" data-post-id="366814">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="asianfilm" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/asianfilm/120/36986_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  asianfilm
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>I know the original comment is about using Claude Code to develop the code base, but I’m wondering if Responses are exclusively an OpenAI thing.</p>
<p>I was under the impression that, say, Claude’s API was compatible with OpenAI’s API, but maybe that is not true for Responses.</p>
<p>I’d just rather give money to Anthropic than OpenAI if paying for credits outside of my Claude Max subscription for Claude Code usage.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="366814" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981/12">Post #11</a>
	                </div>
	            </div>
              <div id="likers-container-366814" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="366814"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #11"></div>
  </section>
</div>
    <div class="postbit" id="366823" data-post-id="366823">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vkryukov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vkryukov/120/39604_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vkryukov
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>OpenAI.Responses is indeed OpenAI-only library, but I develop it using Claude Code, which I think is the current SOTA in terms of the code generation quality.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="366823" data-batch-url="/posts/batch_likers">
                        0
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981/13">Post #12</a>
	                </div>
	            </div>
              <div id="likers-container-366823" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="366823"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #12"></div>
  </section>
</div>
    <div class="postbit" id="367486" data-post-id="367486">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vkryukov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vkryukov/120/39604_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vkryukov
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981" rel="nofollow">openai_responses</a> library has been updated to v0.4.0. This release cleans up both the API and implementation details, and adds improved support for streaming (including streaming JSON events) , structured outputs, and function calling. Additional details can be found in <a href="https://hexdocs.pm/openai_responses/changelog.html#0-4-0" rel="noopener nofollow ugc">Changelog for v0.4.0</a>.</p>
<p>Here are some examples of using the new API from the Livebook <a href="https://hexdocs.pm/openai_responses/tutorial.html" rel="noopener nofollow ugc">Tutorial</a>:</p>
<ol>
<li>You can use a previous response to continue the conversation; OpenAI takes care of keeping the state:</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">alias OpenAI.Responses

Responses.create!(
  input: [
    %{role: :developer, content: "Talk like a pirate."},
    %{role: :user, content: "Write me a haiku about Elixir"}
  ]
)
|&gt; Responses.create!(input: "Which programming language is this haiku about?")
|&gt; Map.get(:text)
|&gt; IO.puts()
# Output contains "Elixir"; still talks like a pirate
</code></pre>
<ol start="2">
<li>Costs are calculated automatically:</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">{:ok, response} = Responses.create("Explain quantum computing")

# All cost values are Decimal for precision
IO.inspect(response.cost)
# =&gt; %{
#      input_cost: #Decimal&lt;0.0004&gt;,
#      output_cost: #Decimal&lt;0.0008&gt;,
#      total_cost: #Decimal&lt;0.0012&gt;,
#      cached_discount: #Decimal&lt;0&gt;
#    }
</code></pre>
<ol start="3">
<li>You can request a <a href="https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses" rel="noopener nofollow ugc">Structured Output</a> and stream JSON events:</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir">Responses.stream(
  input: "List 3 programming languages with their year of creation",
  model: "gpt-4o-mini",
  schema: %{
    languages: {:array, %{
      name: :string,
      year: :integer,
      paradigm: {:string, description: "Main programming paradigm"}
    }}
  }
)
|&gt; Responses.Stream.json_events()
|&gt; Enum.each(&amp;IO.puts/1)
</code></pre>
<ol start="4">
<li>You can define provide access to your own functions and automatically resolve function calls (notice it uses <code>run/2</code> instead of <code>create/1</code>):</li>
</ol>
<pre data-code-wrap="elixir"><code class="lang-elixir"># Define available functions
functions = %{
  "get_weather" =&gt; fn %{"location" =&gt; location} -&gt;
    # In a real app, this would call a weather API
    case location do
      "Paris" -&gt; "15°C, partly cloudy"
      "London" -&gt; "12°C, rainy"
      "New York" -&gt; "8°C, sunny"
      _ -&gt; "Weather data not available"
    end
  end,
  "get_time" =&gt; fn %{"timezone" =&gt; timezone} -&gt;
    # In a real app, this would get actual time for timezone
    case timezone do
      "Europe/Paris" -&gt; "14:30"
      "Europe/London" -&gt; "13:30" 
      "America/New_York" -&gt; "08:30"
      _ -&gt; "Unknown timezone"
    end
  end
}

# Define function tools
weather_tool = Responses.Schema.build_function(
  "get_weather",
  "Get current weather for a location",
  %{location: {:string, description: "City name"}}
)

time_tool = Responses.Schema.build_function(
  "get_time", 
  "Get current time in a timezone",
  %{timezone: {:string, description: "Timezone like Europe/Paris"}}
)

# Run the conversation with automatic function calling
responses = Responses.run(
  [
    input: "What's the weather and time in Paris?",
    tools: [weather_tool, time_tool]
  ],
  functions
)
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="367486" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981/14">Post #13</a>
	                </div>
	            </div>
              <div id="likers-container-367486" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="367486"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #13"></div>
  </section>
</div>
    <div class="postbit" id="368320" data-post-id="368320">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vkryukov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vkryukov/120/39604_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vkryukov
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p><a href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981" rel="nofollow">openai_responses</a> library has been updated to v0.5.1, bringing significant enhancements since v0.4.0. This release adds union type support, manual function calling control, built-in error handling with retry logic, and flexible API options. See the <a rel="nofollow">full changelog</a> for complete details.</p>
<h2><a name="p-368320-union-types-with-anyof-1" class="anchor" href="#p-368320-union-types-with-anyof-1" aria-label="Heading link" rel="nofollow"></a>Union Types with <code>anyOf</code></h2>
<p>Define properties that can be multiple types:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">alias OpenAI.Responses

Responses.create!(
  input: "Generate a product listing",
  schema: %{
    price: {:anyOf, [:number, :string]},  # Can be 29.99 or "$29.99"
    tags: {:anyOf, [:string, {:array, :string}]}  # Can be "electronics" or ["laptop", "gaming"]
  }
)
</code></pre>
<h2><a name="p-368320-manual-function-calling-2" class="anchor" href="#p-368320-manual-function-calling-2" aria-label="Heading link" rel="nofollow"></a>Manual Function Calling</h2>
<p>Take control of function execution with the new <code>call_functions/2</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  # Get a response with function calls
  {:ok, response} = Responses.create(
    input: "What's the weather in Paris and London?",
    tools: [weather_tool]
  )

  # Manually execute functions with custom logic
  outputs = Responses.call_functions(response.function_calls, %{
    "get_weather" =&gt; fn %{"location" =&gt; city} -&gt;
      # Add logging, caching, or modify results
      Logger.info("Weather requested for #{city}")

      weather = fetch_weather_from_api(city)
      %{temperature: weather.temp, conditions: weather.desc, cached_at: DateTime.utc_now()}
    end
  })

  # Continue conversation with enriched results
  {:ok, final} = Responses.create(response, input: outputs)
</code></pre>
<h2><a name="p-368320-error-handling-with-retry-support-3" class="anchor" href="#p-368320-error-handling-with-retry-support-3" aria-label="Heading link" rel="nofollow"></a>Error Handling with Retry Support</h2>
<p>The new <code>OpenAI.Responses.Error</code> module provides intelligent error handling:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  case Responses.create(input: "Hello") do
    {:ok, response} -&gt;
      IO.puts(response.text)

    {:error, error} -&gt;
      if OpenAI.Responses.Error.retryable?(error) do
        # Retry with exponential backoff for 429, 500, 503, or timeout errors
        :timer.sleep(1000)
        # retry the request
      else
        # Handle non-retryable errors
        Logger.error("API error: #{error.message}")
      end
  end
</code></pre>
<h2><a name="p-368320-flexible-api-options-4" class="anchor" href="#p-368320-flexible-api-options-4" aria-label="Heading link" rel="nofollow"></a>Flexible API Options</h2>
<p>All major functions now accept both keyword lists and maps:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">  # Traditional keyword list
  Responses.create(input: "Hello", model: "gpt-4o", temperature: 0.7)

  # Using maps (great for dynamic options)
  options = %{input: "Hello", model: "gpt-4o", temperature: 0.7}
  Responses.create(options)

  # Works with streaming too
  Responses.stream(%{
    input: "Write a story",
    stream: Responses.Stream.delta(&amp;IO.write/1)
  })
</code></pre>
<h2><a name="p-368320-additional-improvements-5" class="anchor" href="#p-368320-additional-improvements-5" aria-label="Heading link" rel="nofollow"></a>Additional Improvements</h2>
<ul>
<li>Model preservation in follow-up responses (no more accidentally switching models)</li>
<li>Function calls now properly handle JSON-encodable return values</li>
<li>Support for string keys in schema definitions (database-friendly)</li>
<li>Cost calculation for new models including o3</li>
<li>Enhanced documentation and LLM usage guide</li>
</ul>
<p>The API remains backward compatible while providing more flexibility and control over your AI interactions.</p> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="368320" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981/15">Post #14</a>
	                </div>
	            </div>
              <div id="likers-container-368320" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="368320"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-standard-post cat-standard-post" title="Post #14"></div>
  </section>
</div>
    <div class="postbit" id="369527" data-post-id="369527">
  <section>
    <div class="post-wrap">


					<div class="post-header">
		        <div class="user-avatar">
		          <img alt="vkryukov" src="https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/vkryukov/120/39604_2.png" width="120" height="120" />
		        </div>
					
						<div class="user-details">
		          <div class="user-name">
		            <h3>
                  vkryukov
                    <span class="op-star" title="Thread Starter">
                      <img alt="OP" class="op-star-icon" src="/assets/thread-icons/thread-icon-thread-starter-df91e872.png" />
                    </span>
                  </h3>
		          </div>
						
						</div>
					
					</div>

	        <div class="thread-main">
	            <div class="post-body" data-turbo="false">
								<p>Hi everyone! I’m excited to announce the release of <a href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981" rel="nofollow">OpenAI.Responses</a> 0.6.0, which includes several improvements and bug fixes since version 0.5.1.</p>
<h2><a name="p-369527-whats-new-1" class="anchor" href="#p-369527-whats-new-1" aria-label="Heading link" rel="nofollow"></a>What’s New</h2>
<h3><a name="p-369527-array-schemas-at-root-level-060-2" class="anchor" href="#p-369527-array-schemas-at-root-level-060-2" aria-label="Heading link" rel="nofollow"></a>Array Schemas at Root Level (0.6.0)</h3>
<p>The biggest feature in this release is automatic support for arrays at the root level of structured output schemas. Previously, OpenAI’s API required the root level to be an object, which meant you had to manually wrap arrays. Now the library handles this transparently:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir"># You can now do this directly!
{:ok, response} = Responses.create(
  input: "List 3 interesting facts about space exploration",
  schema: {:array, %{
    fact: :string,
    year: {:integer, description: "Year of the event"},
    significance: {:string, description: "Why this fact is important"}
  }}
)

# response.parsed is an array directly:
[
  %{"fact" =&gt; "First satellite launch", "year" =&gt; 1957, "significance" =&gt; "Started the space age"},
  %{"fact" =&gt; "Moon landing", "year" =&gt; 1969, "significance" =&gt; "First humans on another celestial body"},
  %{"fact" =&gt; "ISS construction", "year" =&gt; 1998, "significance" =&gt; "Permanent human presence in space"}
]
</code></pre>
<p>The library automatically wraps arrays in an object before sending to the API and unwraps them in the response, making the developer experience seamless.</p>
<h3><a name="p-369527-bug-fixes-3" class="anchor" href="#p-369527-bug-fixes-3" aria-label="Heading link" rel="nofollow"></a>Bug Fixes</h3>
<p><strong>Duplicate Assistant Response Handling (0.5.3)</strong></p>
<p>Fixed an edge case where the OpenAI API sometimes returns duplicate assistant responses. The library now only processes the first assistant response in <code>Response.extract_text/1</code>, preventing duplicate content in your results.</p>
<h3><a name="p-369527-documentation-improvements-052-4" class="anchor" href="#p-369527-documentation-improvements-052-4" aria-label="Heading link" rel="nofollow"></a>Documentation Improvements (0.5.2)</h3>
<ul>
<li>Added comprehensive documentation for the <code>:schema</code> option</li>
<li>Improved examples throughout the codebase</li>
<li>Better explanation of structured output features</li>
</ul>
<h3><a name="p-369527-internal-improvements-052-5" class="anchor" href="#p-369527-internal-improvements-052-5" aria-label="Heading link" rel="nofollow"></a>Internal Improvements (0.5.2)</h3>
<ul>
<li>Refactored input handling to consistently accept both maps and keyword lists with atom or string keys</li>
<li>Fixed all Dialyzer issues for better type safety</li>
<li>Resolved Credo warnings for improved code quality</li>
</ul>
<h2><a name="p-369527-upgrading-6" class="anchor" href="#p-369527-upgrading-6" aria-label="Heading link" rel="nofollow"></a>Upgrading</h2>
<p>To upgrade to the latest version, update your <code>mix.exs</code>:</p>
<pre data-code-wrap="elixir"><code class="lang-elixir">def deps do
  [
    {:openai_responses, "~&gt; 0.6.0"}
  ]
end
</code></pre>
<p>Then run:</p>
<pre data-code-wrap="bash"><code class="lang-bash">mix deps.update openai_responses
</code></pre> 
	            </div>

	            <div class="base-line">
	                <div class="thread-counters">
	                    <span class="thread-count count-likes js-likers-trigger" title="Likes" data-post-id="369527" data-batch-url="/posts/batch_likers">
                        1
                      </span>
                      <!-- <span class="thread-count js-solved-indicator" title="Marked as solution"></span> -->
	                </div>
	                <div class="go-to-post">
	                  <a title="Go to post" alt="Go to post" href="https://forum.elixirforum.com/t/openai-responses-a-client-for-openais-new-responses-api/69981/16">Post #15</a>
	                </div>
	            </div>
              <div id="likers-container-369527" 
                   class="likers-container"
                   data-first-post="false"
                   data-batch-url="/posts/batch_likers">
                   <div class="likers-placeholder" 
                     data-likers-post-id="369527"
                     data-batch-url="/posts/batch_likers">
                  <div class="post-likers"></div>
                </div>
              </div>
	        </div>
			

    </div>

    <div class="triangle-top-right type-last-post cat-last-post" title="Last post!"></div>
  </section>
</div>
</template></turbo-stream><turbo-stream action="replace" target="load-more-container"><template><div id="load-more-container" class="load-more-container">
    <span class="all-loaded">— All posts loaded —</span>
</div></template></turbo-stream>