callTogetherAiApi = async (apiRequestBody, apiKey) => {
  const response = await fetch('https://api.together.xyz/v1/chat/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      Authorization: `Bearer ${apiKey}`,
    },
    body: JSON.stringify(apiRequestBody),
  });
  if (!response.ok) {
    const errData = await response.json().catch(() => ({}));
    console.error('Together AI API Error Response:', errData);
    const errorMessage = errData.error && errData.error.message ? errData.error.message : `API Error: ${response.status}`;
    throw new Error(errorMessage);
  }
  return response.json();
}
Helper functions and constants for Together AI API Example
We are using LLMs to classify text or analyze a picture taken by the user's camera.