Application - Query
Learn how to query your application using our API.
In this section, we will guide you on how to use the api/applications/:applicationId/query
endpoint to query your custom applications.
The response of this endpoint is streamed.
This means that the server sends the response in chunks, which can be processed by the client as they arrive. This is particularly useful when dealing with LLMs.
cURL Example
Here is an example of how to use cURL to query a custom application:
curl --request POST \
--url https://generatedby.com/api/applications/APPLICATION_ID/query \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer API_KEY' \
--data '{
// your query data
}'
Replace APPLICATION_ID & API_KEY with your API key.
JavaScript Example
Here is an example of how to use fetch with JavaScript to query a custom application:
const applicationId = "APPLICATION_ID"
const url = `https://generatedby.com/api/applications/${applicationId}/query`
const data = {
// your query data
}
async function fetchData() {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer API_KEY",
},
body: JSON.stringify(data),
})
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`)
}
const reader = response.body.getReader()
const decoder = new TextDecoder()
let done = false
let text = ""
while (!done) {
const { value, done: doneReading } = await reader.read()
done = doneReading
const chunkValue = decoder.decode(value, { stream: true })
text += chunkValue
console.log(text)
}
} catch (error) {
console.error("Error:", error)
}
}
fetchData()
Replace APPLICATION_ID & API_KEY with your API key.
In this updated example, we're using the getReader() method of the Response.body to get a ReadableStream of the response. We then read chunks from the stream using the read() method, and decode each chunk as it arrives using the TextDecoder interface.
For more details on how to use the API, please refer to the API section of the documentation.