api.example.com/*: service none (for normal origins)*/* to match all or *.example.com/* to match all subdomains besides apex, service: Worker*.workers.example.com)

fetch subrequest isn't going to use up any CPUdo stuff with reader?the event stream might not finish within 30sIt's 30 seconds of CPU time, none of this is particularly heavy compute.
const response = await ... and then return response, couldn't you?


Or you can put the vars in your wrangler.toml
<script> on the html 
<script> that grabs the static files from static.domain.com R2wrangler and then invoke an older deployed version that hasn't been updated to the new code?api.example.com/**.example.com/**.workers.example.comdo stuff with readerconst response = await ...return response<script><script>static.domain.com const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${env.OPENAI_API_KEY}`,
},
body,
})
.then((res) => response.body)
.then((body) => {
const reader = body.getReader()
// do stuff with reader
})const startTime = Date.now()
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${env.OPENAI_API_KEY}`,
},
body,
})
if (!response.ok) {
console.log(
`Unexpected response from OpenAI API: ${response.status} ${response.statusText}`
)
return
}
if (!response.body) {
console.log("No response body")
return
}
const reader = response.body.getReader()
// Get first byte
let chunk = await reader.read()
// Log first byte time
const firstByteTime = Date.now() - startTime
// Read the rest of the response
while (!chunk.done) {
chunk = await reader.read()
} const totalTime = Date.now() - startTime
console.log("Time to first byte: " + firstByteTime + "ms")
console.log("Total response time: " + totalTime + "ms")
// Log response time
const client = new Client(env.DB_URL + "?sslmode=require")
await client.connect()
const text =
"INSERT INTO response_times(model, date, ttfb, duration) VALUES($1, $2, $3, $4) RETURNING *"
const values = [
"gpt-4",
new Date(event.scheduledTime),
firstByteTime,
totalTime,
]
try {
const res = await client.query(text, values)
console.log(res.rows[0])
} catch (err) {
console.error(err)
} finally {
ctx.waitUntil(client.end())
}const [client, webSocket] = Object.values(webSocketPair);const {client, webSocket} = webSocketPair;