---
title: "Supabase"
url: "/docs/observability/supabase_integration"
canonical_url: "https://docs.litellm.ai/docs/observability/supabase_integration"
type: "docs"
last_updated: "2026-10-08"
related:
  - "/docs/observability/sumologic_integration"
  - "/docs/observability/zerobus"
---
# Supabase

> Index of all LiteLLM docs: https://docs.litellm.ai/llms.txt


:::tip

這是由社群維護的文件，如果您遇到 bug，請提出 issue
https://github.com/BerriAI/litellm

:::

[Supabase](https://supabase.com/) 是開源的 Firebase 替代方案。
從 Postgres 資料庫、Authentication、即時 API、Edge Functions、Realtime subscriptions、Storage 和 Vector embeddings 開始您的專案。

## 使用 Supabase 記錄請求，並查看所有 LLM 提供者（OpenAI、Azure、Anthropic、Cohere、Replicate、PaLM）的總支出 {#use-supabase-to-log-requests-and-see-total-spend-across-all-llm-providers-openai-azure-anthropic-cohere-replicate-palm}
liteLLM 提供 `success_callbacks` 和 `failure_callbacks`，讓您可以根據回應的狀態，輕鬆將資料傳送到特定提供者。 

在這個情況下，我們希望在兩種情境下都將請求記錄到 Supabase——成功與失敗時。 

### 建立 supabase 資料表  {#create-a-supabase-table}

前往您的 Supabase 專案 > 前往 [Supabase SQL Editor](https://supabase.com/dashboard/projects) 並依照此設定建立新的資料表。

注意：您可以變更資料表名稱，但不要變更欄位名稱。 

```sql
create table
  public.request_logs (
    id bigint generated by default as identity,
    created_at timestamp with time zone null default now(),
    model text null default ''::text,
    messages json null default '{}'::json,
    response json null default '{}'::json,
    end_user text null default ''::text,
    status text null default ''::text,
    error json null default '{}'::json,
    response_time real null default '0'::real,
    total_cost real null,
    additional_details json null default '{}'::json,
    litellm_call_id text unique,
    primary key (id)
  ) tablespace pg_default;
```

### 使用回呼  {#use-callbacks}
只要 2 行程式碼，就能立即透過 Supabase 查看成本並記錄您的回應，**涵蓋所有提供者**： 

```python
litellm.success_callback=["supabase"]
litellm.failure_callback=["supabase"]
```

完整程式碼
```python
from litellm import completion

## set env variables
### SUPABASE
os.environ["SUPABASE_URL"] = "your-supabase-url" 
os.environ["SUPABASE_KEY"] = "your-supabase-key" 

## LLM API KEY
os.environ["OPENAI_API_KEY"] = ""

# set callbacks
litellm.success_callback=["supabase"]
litellm.failure_callback=["supabase"]

# openai call
response = completion(
  model="gpt-5.6-luna", 
  messages=[{"role": "user", "content": "Hi 👋 - i'm openai"}],
  user="ishaan22" # identify users
) 

# bad call, expect this call to fail and get logged
response = completion(
  model="chatgpt-test", 
  messages=[{"role": "user", "content": "Hi 👋 - i'm a bad call to test error logging"}]
)
 
```

### 其他控制項  {#additional-controls}

**識別終端使用者**

傳入 `user` 至 `litellm.completion`，即可將您的 llm 呼叫對應到終端使用者。 

```python
response = completion(
  model="gpt-5.6-luna", 
  messages=[{"role": "user", "content": "Hi 👋 - i'm openai"}],
  user="ishaan22" # identify users
) 
```

**不同的資料表名稱**

如果您修改了資料表名稱，以下是傳入新名稱的方式。

```python 
litellm.modify_integration("supabase",{"table_name": "litellm_logs"})
```

## 支援與創辦人交流 {#support--talk-to-founders}

- [預約示範 👋](https://calendly.com/d/4mp-gd3-k5k/berriai-1-1-onboarding-litellm-hosted-version)
- [社群 Discord 💭](https://discord.gg/wuPM9dRgDw)
- 我們的電子郵件 ✉️ ishaan@berri.ai / krrish@berri.ai

## Related pages

- [Sumo Logic](https://docs.litellm.ai/docs/observability/sumologic_integration.md)
- [Databricks Zerobus](https://docs.litellm.ai/docs/observability/zerobus.md)
