"use client"; import React, { useState, useEffect, useRef } from "react"; import { Button, TextInput, Grid, Col } from "@tremor/react"; import { Card, Metric, Text } from "@tremor/react"; import { Button as Button2, Modal, Form, Input, InputNumber, Select, message, } from "antd"; import { keyCreateCall } from "./networking"; const { Option } = Select; interface CreateKeyProps { userID: string; userRole: string | null; accessToken: string; data: any[] | null; userModels: string[]; setData: React.Dispatch>; } const CreateKey: React.FC = ({ userID, userRole, accessToken, data, userModels, setData, }) => { const [form] = Form.useForm(); const [isModalVisible, setIsModalVisible] = useState(false); const [apiKey, setApiKey] = useState(null); const handleOk = () => { setIsModalVisible(false); form.resetFields(); }; const handleCancel = () => { setIsModalVisible(false); setApiKey(null); form.resetFields(); }; const handleCreate = async (formValues: Record) => { try { message.info("Making API Call"); setIsModalVisible(true); const response = await keyCreateCall(accessToken, userID, formValues); setData((prevData) => (prevData ? [...prevData, response] : [response])); // Check if prevData is null setApiKey(response["key"]); message.success("API Key Created"); form.resetFields(); localStorage.removeItem("userData" + userID); } catch (error) { console.error("Error creating the key:", error); } }; return (
{userRole === "App Owner" || userRole === "Admin" ? ( <> ) : ( <> )}
Create Key
{apiKey && (

Please save this secret key somewhere safe and accessible. For security reasons, you will not be able to view it again{" "} through your LiteLLM account. If you lose this secret key, you will need to generate a new one.

{apiKey != null ? ( API Key: {apiKey} ) : ( Key being created, this might take 30s )}
)}
); }; export default CreateKey;