"use client"; import React, { useState, useEffect, useRef } from "react"; import { Button, TextInput, Grid, Col } from "@tremor/react"; import { Card, Metric, Text, Title, Subtitle, Accordion, AccordionHeader, AccordionBody, } from "@tremor/react"; import { CopyToClipboard } from 'react-copy-to-clipboard'; import { Button as Button2, Modal, Form, Input, InputNumber, Select, message, } from "antd"; import { keyCreateCall, slackBudgetAlertsHealthCheck, modelAvailableCall } from "./networking"; const { Option } = Select; interface CreateKeyProps { userID: string; team: any | null; userRole: string | null; accessToken: string; data: any[] | null; setData: React.Dispatch>; } const CreateKey: React.FC = ({ userID, team, userRole, accessToken, data, setData, }) => { const [form] = Form.useForm(); const [isModalVisible, setIsModalVisible] = useState(false); const [apiKey, setApiKey] = useState(null); const [softBudget, setSoftBudget] = useState(null); const [userModels, setUserModels] = useState([]); const [modelsToPick, setModelsToPick] = useState([]); const handleOk = () => { setIsModalVisible(false); form.resetFields(); }; const handleCancel = () => { setIsModalVisible(false); setApiKey(null); form.resetFields(); }; useEffect(() => { const fetchUserModels = async () => { try { if (userID === null || userRole === null) { return; } if (accessToken !== null) { const model_available = await modelAvailableCall(accessToken, userID, userRole); let available_model_names = model_available["data"].map( (element: { id: string }) => element.id ); console.log("available_model_names:", available_model_names); setUserModels(available_model_names); } } catch (error) { console.error("Error fetching user models:", error); } }; fetchUserModels(); }, [accessToken, userID, userRole]); const handleCreate = async (formValues: Record) => { try { message.info("Making API Call"); setIsModalVisible(true); const response = await keyCreateCall(accessToken, userID, formValues); console.log("key create Response:", response); setData((prevData) => (prevData ? [...prevData, response] : [response])); // Check if prevData is null setApiKey(response["key"]); setSoftBudget(response["soft_budget"]); message.success("API Key Created"); form.resetFields(); localStorage.removeItem("userData" + userID); } catch (error) { console.error("Error creating the key:", error); } }; const handleCopy = () => { message.success('API Key copied to clipboard'); }; useEffect(() => { let tempModelsToPick = []; if (team) { if (team.models.length > 0) { if (team.models.includes("all-proxy-models")) { // if the team has all-proxy-models show all available models tempModelsToPick = userModels; } else { // show team models tempModelsToPick = team.models; } } else { // show all available models if the team has no models set tempModelsToPick = userModels; } } else { // no team set, show all available models tempModelsToPick = userModels; } setModelsToPick(tempModelsToPick); }, [team, userModels]); return (
<> Optional Settings { if (value && team && team.max_budget !== null && value > team.max_budget) { throw new Error(`Budget cannot exceed team max budget: $${team.max_budget}`); } }, }, ]} > { if (value && team && team.tpm_limit !== null && value > team.tpm_limit) { throw new Error(`TPM limit cannot exceed team TPM limit: ${team.tpm_limit}`); } }, }, ]} > { if (value && team && team.rpm_limit !== null && value > team.rpm_limit) { throw new Error(`RPM limit cannot exceed team RPM limit: ${team.rpm_limit}`); } }, }, ]} >
Create Key
{apiKey && ( Save your Key

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;