Loading...
const res = await fetch(LLM_API_URL, {
method: 'POST',
headers: { Authorization: 'Bearer ' + 'my-secret-key' },
body: JSON.stringify({ messages }),
});const res = await fetch(process.env.LLM_API_URL, {
method: 'POST',
headers: { Authorization: 'Bearer ' + process.env.LLM_API_KEY },
body: JSON.stringify({ messages, max_tokens: 1024 }),
signal: AbortSignal.timeout(60_000),
});The call runs on the server with the key from the environment, an output token limit and a timeout.
Not with your secret key. Send requests to your own server, which adds the key, or use short-lived tokens where the provider supports them.
Cost scales with the text the model reads and writes. Input and output tokens are counted separately, and output tokens usually cost more.
The system message sets instructions and behavior for the whole conversation. User messages contain the requests the model answers.