REST API Endpoints Needed for Raycast Extension Development

I’m developing a Raycast extension (a macOS productivity tool) to integrate Sambanova Cloud capabilities, but the Python-only SDK makes this challenging since Raycast extensions use Node.js - are there any plans to provide REST API endpoints, or what would be the recommended approach for Node.js integration?

1 Like

@anongecko

Thank you for Joining the community. I can open a feature request for a node specific SDK to the product team.

in the mean time you can work around that a few ways leveraging some native node functionality such as

https module

const https = require('https');

const options = {
  hostname: 'api.sambanova.ai',
  path: '/v1/chat/completions',
  method: 'POST',
  headers: {
    'Authorization': 'Bearer <your-api-key>',
    'Content-Type': 'application/json'
  }
};

const data = JSON.stringify({
  "stream": true,
  "model": "Meta-Llama-3.3-70B-Instruct",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant"
    },
    {
      "role": "user",
      "content": "Hello"
    }
  ]
});

const req = https.request(options, (res) => {
  let response = '';

  res.on('data', (chunk) => {
    response += chunk;
  });

  res.on('end', () => {
    try {
      const parsedData = JSON.parse(response);
      console.log(parsedData);
    } catch (error) {
      console.error('Error parsing JSON:', error);
    }
  });
});

req.on('error', (error) => {
  console.error('Error making request:', error);
});

req.write(data);
req.end();

axios library

const axios = require('axios');

const url = 'https://api.sambanova.ai/v1/chat/completions';
const headers = {
  'Authorization': 'Bearer <your-api-key>',
  'Content-Type': 'application/json'
};
const data = {
  "stream": true,
  "model": "Meta-Llama-3.3-70B-Instruct",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant"
    },
    {
      "role": "user",
      "content": "Hello"
    }
  ]
};

axios.post(url, data, { headers })
  .then((response) => {
    console.log(response.data);
  })
  .catch((error) => {
    console.error(error);
  });

node-fetch library

const fetch = require('node-fetch');

const url = 'https://api.sambanova.ai/v1/chat/completions';
const headers = {
  'Authorization': 'Bearer <your-api-key>',
  'Content-Type': 'application/json'
};
const data = {
  "stream": true,
  "model": "Meta-Llama-3.3-70B-Instruct",
  "messages": [
    {
      "role": "system",
      "content": "You are a helpful assistant"
    },
    {
      "role": "user",
      "content": "Hello"
    }
  ]
};

fetch(url, {
  method: 'POST',
  headers,
  body: JSON.stringify(data)
})
  .then((response) => response.json())
  .then((data) => {
    console.log(data);
  })
  .catch((error) => {
    console.error(error);
  });

1 Like