Skip to content

How to make it work for OpenAI API calls? #1

@bachl

Description

@bachl

Hi, thank you so much for this amazing work. Enabling httr2 will be a major upgrade for my teaching materials :)

I have a question on whether it is possible to use APIs like the OpenAI API via httr2 with this approach.

This works for me:

request(base_url = "https://api.breakingbadquotes.xyz/v1/quotes") |> req_perform()

This gives an error:

request(base_url = "https://api.openai.com/v1/chat/completions") |> 
  req_auth_bearer_token(key) |>  # has been set
  req_body_json(list(
    model = "gpt-4.1-nano",
    messages = list(
      list(role = "system", content = "You are a funny jokster"),
      list(role = "user", content = "Tell me a joke.")
    )
  )) |> 
  req_perform()
Error in `req_perform()` at /tmp/.webRtmp-source:1:1:
! HTTP 429 Too Many Requests.
Run `rlang::last_trace()` to see where the error occurred.

Again, thank you for your fantastic work on webr. This is an amazing teaching resource.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions