Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

refactor(ui): migrate api-reference to shadcn (#34263)

yuneng-jiang0b7b5100d0b0
diff --git a/ui/litellm-dashboard/eslint-suppressions.json b/ui/litellm-dashboard/eslint-suppressions.json
index 6072c8c725b..d4826ba47b1 100644
--- a/ui/litellm-dashboard/eslint-suppressions.json
+++ b/ui/litellm-dashboard/eslint-suppressions.json
@@ -65,11 +65,6 @@
"count": 2
}
},
- "src/app/(dashboard)/api-reference/_components/APIReferenceView.tsx": {
- "no-restricted-imports": {
- "count": 1
- }
- },
"src/app/(dashboard)/budgets/_components/budget_modal.tsx": {
"no-restricted-imports": {
"count": 1
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.test.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.test.tsx
index 66fa0dfa63f..ad1cf28dc54 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.test.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.test.tsx
@@ -1,4 +1,5 @@
-import { render } from "@testing-library/react";
+import { render, screen } from "@testing-library/react";
+import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
import APIReferenceView from "./APIReferenceView";
@@ -44,4 +45,48 @@ describe("APIReferenceView", () => {
expect(renderedCode).toContain(apiDocUrl);
expect(renderedCode).not.toContain(proxyUrl);
});
+
+ it("renders the page title, blurb and docs link", () => {
+ render(<APIReferenceView proxySettings={{ PROXY_BASE_URL: "https://proxy.litellm.test" }} />);
+
+ expect(screen.getByText("OpenAI Compatible Proxy: API Reference")).toBeTruthy();
+ expect(screen.getByText(/LiteLLM is OpenAI Compatible/)).toBeTruthy();
+
+ const docsLink = screen.getByRole("link", { name: /API Reference Docs/ });
+ expect(docsLink.getAttribute("href")).toBe("https://docs.litellm.ai/docs/proxy/user_keys");
+ expect(docsLink.getAttribute("target")).toBe("_blank");
+ });
+
+ it("exposes the three SDK tabs with the first selected by default", () => {
+ render(<APIReferenceView proxySettings={{ PROXY_BASE_URL: "https://proxy.litellm.test" }} />);
+
+ expect(screen.getAllByRole("tab").map((tab) => tab.textContent)).toEqual([
+ "OpenAI Python SDK",
+ "LlamaIndex",
+ "Langchain Py",
+ ]);
+ expect(screen.getAllByRole("tab").map((tab) => tab.getAttribute("aria-selected"))).toEqual([
+ "true",
+ "false",
+ "false",
+ ]);
+ });
+
+ it.each([
+ ["OpenAI Python SDK", "import openai"],
+ ["LlamaIndex", "from llama_index.llms import AzureOpenAI"],
+ ["Langchain Py", "from langchain.chat_models import ChatOpenAI"],
+ ])("selecting %s shows its snippet wired to the base url", async (tabName, marker) => {
+ const proxyUrl = "https://proxy.litellm.test";
+ const user = userEvent.setup();
+ render(<APIReferenceView proxySettings={{ PROXY_BASE_URL: proxyUrl }} />);
+
+ await user.click(screen.getByRole("tab", { name: tabName }));
+
+ expect(screen.getByRole("tab", { name: tabName }).getAttribute("aria-selected")).toBe("true");
+
+ const selectedPanel = screen.getByRole("tabpanel");
+ expect(selectedPanel.textContent).toContain(marker);
+ expect(selectedPanel.textContent).toContain(proxyUrl);
+ });
});
diff --git a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.tsx b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.tsx
index 333bd1cad13..9342017ed3f 100644
--- a/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.tsx
+++ b/ui/litellm-dashboard/src/app/(dashboard)/api-reference/_components/APIReferenceView.tsx
@@ -1,7 +1,7 @@
"use client";
import React from "react";
-import { Text, Tab, TabGroup, TabList, TabPanel, TabPanels, Grid } from "@tremor/react";
import CodeBlock from "@/components/CodeBlock";
+import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import DocLink from "./DocLink";
interface ApiRefProps {
@@ -21,33 +21,35 @@ const APIReferenceView: React.FC<ApiRefProps> = ({ proxySettings }) => {
}
return (
- <>
- <Grid className="gap-2 p-8 h-[80vh] w-full mt-2">
- <div className="mb-5">
- {/* Header row with Docs link on the right */}
- <div className="flex items-center justify-between">
- <p className="text-2xl text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold">
- OpenAI Compatible Proxy: API Reference
- </p>
- <DocLink className="ml-3 shrink-0" href="https://docs.litellm.ai/docs/proxy/user_keys" />
- </div>
-
- <Text className="mt-2 mb-2">
- LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url
- to point to your litellm proxy. Example Below{" "}
- </Text>
-
- <TabGroup>
- <TabList>
- <Tab>OpenAI Python SDK</Tab>
- <Tab>LlamaIndex</Tab>
- <Tab>Langchain Py</Tab>
- </TabList>
- <TabPanels>
- <TabPanel>
- <CodeBlock
- language="python"
- code={`import openai
+ <div className="grid grid-cols-1 gap-2 p-8 h-[80vh] w-full mt-2">
+ <div className="mb-5">
+ {/* Header row with Docs link on the right */}
+ <div className="flex items-center justify-between">
+ <h1 className="text-2xl font-semibold text-foreground">OpenAI Compatible Proxy: API Reference</h1>
+ <DocLink className="ml-3 shrink-0" href="https://docs.litellm.ai/docs/proxy/user_keys" />
+ </div>
+
+ <p className="mt-2 mb-2 text-sm text-muted-foreground">
+ LiteLLM is OpenAI Compatible. This means your API Key works with the OpenAI SDK. Just replace the base_url to
+ point to your litellm proxy. Example Below{" "}
+ </p>
+
+ <Tabs defaultValue="openai">
+ <TabsList variant="line" className="border-b rounded-none w-full justify-start h-auto p-0">
+ <TabsTrigger value="openai" className="rounded-none px-4 py-2 flex-none">
+ OpenAI Python SDK
+ </TabsTrigger>
+ <TabsTrigger value="llamaindex" className="rounded-none px-4 py-2 flex-none">
+ LlamaIndex
+ </TabsTrigger>
+ <TabsTrigger value="langchain" className="rounded-none px-4 py-2 flex-none">
+ Langchain Py
+ </TabsTrigger>
+ </TabsList>
+ <TabsContent value="openai">
+ <CodeBlock
+ language="python"
+ code={`import openai
client = openai.OpenAI(
api_key="your_api_key",
base_url="${base_url}" # LiteLLM Proxy is OpenAI compatible, Read More: https://docs.litellm.ai/docs/proxy/user_keys
@@ -64,13 +66,13 @@ response = client.chat.completions.create(
)
print(response)`}
- />
- </TabPanel>
+ />
+ </TabsContent>
- <TabPanel>
- <CodeBlock
- language="python"
- code={`import os, dotenv
+ <TabsContent value="llamaindex">
+ <CodeBlock
+ language="python"
+ code={`import os, dotenv
from llama_index.llms import AzureOpenAI
from llama_index.embeddings import AzureOpenAIEmbedding
@@ -98,13 +100,13 @@ index = VectorStoreIndex.from_documents(documents, service_context=service_conte
query_engine = index.as_query_engine()
response = query_engine.query("What did the author do growing up?")
print(response)`}
- />
- </TabPanel>
+ />
+ </TabsContent>
- <TabPanel>
- <CodeBlock
- language="python"
- code={`from langchain.chat_models import ChatOpenAI
+ <TabsContent value="langchain">
+ <CodeBlock
+ language="python"
+ code={`from langchain.chat_models import ChatOpenAI
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
@@ -129,13 +131,11 @@ messages = [
response = chat(messages)
print(response)`}
- />
- </TabPanel>
- </TabPanels>
- </TabGroup>
- </div>
- </Grid>
- </>
+ />
+ </TabsContent>
+ </Tabs>
+ </div>
+ </div>
);
};