File size: 1,056 Bytes
4ec8dba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { useState, useEffect } from 'react';

const CodeBlock = ({ token }) => {
  const codeWithToken = `${token}`;

  return (
    <pre>
      {token ? codeWithToken : ""}
    </pre>
  );
};

const TokenGen = () => {
  const [token, setToken] = useState(null);

  useEffect(() => {
    const generateToken = async () => {
      try {
        const response = await fetch('https://proxy.litellm.ai/key/new', {
          method: 'POST',
          headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer sk-liteplayground',
          },
          body: JSON.stringify({'total_budget': 100})
        });
        
        if (!response.ok) {
          throw new Error('Network response was not ok');
        }
        
        const data = await response.json();

        setToken(`${data.api_key}`);
    } catch (error) {
      console.error('Failed to fetch new token: ', error);
    }
  };

  generateToken();
}, []);

return (
  <div>
    <CodeBlock token={token} />
  </div>
);
};

export default TokenGen;