튜토리얼: 사용자, 팀, 프로젝트별로 재단 모델 지출 추적

이 튜토리얼에서는 Unity Gateway에서 기초 모델 지출을 촉진하는 요인을 분석합니다. 귀하가 관리하는 모델 서비스 전반에서 사용자별로 비용을 할당한 다음, 시스템 테이블을 사용해 팀, 프로젝트 또는 사용 사례별 비용을 추적할 수 있도록 태그를 추가합니다:

Prerequisites

메모

이 튜토리얼의 금액 추정은 정가를 기준으로 합니다. 협상된 할인과 청구 크레딧은 제외됩니다. 귀속 및 추세 분석에 사용하고, 청구 명세서는 조정에 활용하세요.

1단계: 어떤 사용자가 지출을 주도하는지 확인하세요

Tip

지니 코드 (에이전트 모드)는 이 작업을 수행할 수 있습니다. 다음 예제 프롬프트를 사용해 보세요.

Query system.billing.usage for MODEL_SERVING records from the past 30 days where usage_metadata.ai_gateway.endpoint_name is set. Convert DBUs to list-price USD using system.billing.list_prices at the price effective for each record, break down by model service, destination model, and requesting user, and sort by cost.

AI 게이트웨이 > 사용 > 대시보드 >비용 분석으로 가보세요. 이 기능은 SQL을 작성하지 않고도 Databricks 제공 또는 외부 제공자 모델, 엔드포인트, 사용자별로 지출을 세분화합니다. 비용 분석 아래의 비용(USD) 기준 상위 사용자 차트는 지출이 많은 상위 사용자의 순위를 보여줍니다.

또는 시스템 테이블을 직접 쿼리하여 누가 어디에서 가장 많이 소비하는지 확인할 수도 있습니다. 쿼리하는 테이블은 모델 유형에 따라 다릅니다:

Databricks 제공 모델

system.billing.usage를 쿼리하고 system.billing.list_prices를 조인하여 DBU 사용량을 달러로 환산하세요. 필드는 identity_metadata.run_by 각 요청을 발행한 주체를 식별합니다:

SELECT
 u.usage_metadata.ai_gateway.endpoint_name AS model_service_name,
 u.usage_metadata.ai_gateway.destination_model AS destination_model,
 u.identity_metadata.run_by AS run_by,
 SUM(u.usage_quantity * lp.pricing.effective_list.default) AS list_cost_usd
FROM system.billing.usage u
JOIN system.billing.list_prices lp
 ON  u.sku_name  = lp.sku_name
 AND u.cloud     = lp.cloud
 AND u.usage_unit = lp.usage_unit
 AND u.usage_end_time >= lp.price_start_time
 AND (lp.price_end_time IS NULL OR u.usage_end_time < lp.price_end_time)
WHERE u.billing_origin_product = 'MODEL_SERVING'
 AND u.usage_metadata.ai_gateway.endpoint_name IS NOT NULL
 AND u.identity_metadata.run_by IS NOT NULL
 AND u.usage_unit = 'DBU'
 AND lp.currency_code = 'USD'
 AND u.usage_date >= current_date() - INTERVAL 30 DAYS
GROUP BY model_service_name, destination_model, run_by
ORDER BY list_cost_usd DESC;

외부 모델

모델 제공자 서비스를 통해 외부 제공자로 라우팅된 요청의 경우, Azure Databricks는 토큰 사용과 제공자가 공개한 가격system.ai_gateway.external_model_spend에 따라 USD 단위 비용을 추정합니다. 이 쿼리는 Azure Databricks가 제공하는 모델 제공자 서비스에 대한 쿼리와 동일한 분류를 반환합니다:

SELECT
  usage_metadata.endpoint_name AS model_provider_service_name,
  identity_metadata.run_by AS run_by,
  SUM(usage_quantity) AS estimated_provider_cost_usd
FROM system.ai_gateway.external_model_spend
WHERE identity_metadata.run_by IS NOT NULL
  AND usage_start_time >= current_timestamp() - INTERVAL 30 DAYS
GROUP BY run_by, model_provider_service_name
ORDER BY estimated_provider_cost_usd DESC;

2단계: 팀 또는 프로젝트별로 사용량과 지출 추적 설정

사용자별 지출은 누가 지출했는지는 알려주지 않고, 어떤 팀이나 프로젝트인지 알려주지 않습니다. 팀이나 프로젝트에 토큰 사용을 귀속시키려면, 모델 서비스가 팀이나 프로젝트에 어떻게 매핑되는지에 따라 트래픽을 태그하세요:

  • 서비스(엔드포인트) 태그: 각 팀이나 프로젝트가 자체 모델 서비스를 가질 때. 태그는 해당 모델 서비스를 통해 라우팅되는 모든 요청에 적용되므로 한 번 설정하면 됩니다.
  • 요청 태그: 여러 팀이나 프로젝트가 동일한 모델 서비스를 공유할 때. 호출자는 요청마다 태그를 설정하므로, 공유 서비스 내에서 사용량을 귀속시킵니다.

서비스 태그

모델 서비스에 team 또는 project와 같은 태그를 추가하세요. 이 채널을 통해 라우팅되는 모든 요청은 태그를 상속받습니다.

  1. 작업 공간 UI에서 AI 게이트웨이 로 가서 모델 서비스를 열어보세요.
  2. 모델 서비스 개요 페이지의 태그 섹션 아래에 .와 같은 team = ml-platform태그를 추가하세요.

서비스 태그는 endpoint_tagssystem.ai_gateway.usage 필드에 표시되며 custom_tagssystem.billing.usage 필드로 전파됩니다. 모델 서비스 생성 및 구성에 관한 자세한 내용은 모델 API 생성 및 관리 (모델 서비스)을 참조하세요.

요청 태그

project HTTP 헤더(문자열 키를 문자열 값에 매핑하는 JSON 객체)를 사용해 개별 요청에 Databricks-Ai-Gateway-Request-Tags와 같은 태그를 추가합니다:

Databricks-Ai-Gateway-Request-Tags: {"project": "chatbot", "team": "ml-platform"}

요청 태그는 request_tagssystem.ai_gateway.usage 필드에 표시됩니다. OpenAI SDK, Anthropic SDK, REST API로 헤더를 설정한 예시는 사용 추적을 위한 태그 요청을 참조하세요.

메모

비용 귀속에 어떤 태그를 사용할지는 모델에 따라 다릅니다:

  • Azure Databricks에서 제공하는 모델: 서비스 태그를 사용합니다. 서비스 태그만 system.billing.usage로 전파됩니다.
  • 외부 제공자 모델: 서비스 태그 또는 요청 태그를 사용합니다. 두 가지 모두 system.ai_gateway.external_model_spend로 전달되며, 여기서 외부 모델 사용 비용 추정치를 기록합니다.

3단계: 팀 또는 프로젝트별 사용 분석

Tip

지니 코드 (에이전트 모드)는 이 작업을 수행할 수 있습니다. 다음 예제 프롬프트를 사용해 보세요.

Query system.ai_gateway.usage for the past 30 days to show request count and total tokens by the 'team' service tag in endpoint_tags, model service, and destination model. Sort by total tokens, highest first.

태그가 설정되면 사용을 집계system.ai_gateway.usage하여 Azure Databricks 제공 및 외부 제공자 모델로 라우팅되는 모든 요청에 대한 요청 및 토큰 지표를 포착합니다. 서비스 태그는 endpoint_tags['team']별로, 요청 태그는 request_tags['project']별로 그룹화:

서비스 태그

SELECT
  endpoint_tags['team'] AS team,
  endpoint_name,
  destination_model,
  COUNT(*) AS request_count,
  SUM(total_tokens) AS total_tokens
FROM system.ai_gateway.usage
WHERE endpoint_tags['team'] IS NOT NULL
GROUP BY endpoint_tags['team'], endpoint_name, destination_model
ORDER BY total_tokens DESC;

요청 태그

SELECT
  request_tags['project'] AS project,
  endpoint_name,
  destination_model,
  COUNT(*) AS request_count,
  SUM(total_tokens) AS total_tokens
FROM system.ai_gateway.usage
WHERE request_tags['project'] IS NOT NULL
GROUP BY request_tags['project'], endpoint_name, destination_model
ORDER BY total_tokens DESC;

SQL 없이 두 가지 내역을 탐색하려면 비용 분석 페이지의 태그 필터를 사용하세요.

4단계: 팀별 또는 프로젝트별 달러 지출 분석하기

Tip

지니 코드 (에이전트 모드)는 이 작업을 수행할 수 있습니다. 다음 예제 프롬프트를 사용해 보세요.

Query system.billing.usage for MODEL_SERVING records from the past 30 days where usage_metadata.ai_gateway.endpoint_name is set. Convert DBUs to list-price USD using system.billing.list_prices at the price effective for each record, group by the 'team' service tag in custom_tags, and sort by cost.

태그를 설정하면 USD 기준 지출을 팀이나 프로젝트에 배정할 수 있습니다. SQL을 작성하지 않고 태그별로 지출을 그룹화하려면 AI 게이트웨이 > 사용 > 대시보드 >비용 분석 에 들어가 태그 기반 비용 분석 섹션을 사용하세요. 엔드포인트 태그 또는 요청 태그로 필터링하여 엔드포인트 태그 그룹별 비용요청 태그 그룹별 예상 비용을 확인하세요.

SQL로 비용 부여를 하려면, 쿼리하는 테이블은 모델 유형에 따라 다릅니다:

Databricks 제공 모델

서비스 태그는 custom_tagssystem.billing.usage 필드로 전파되므로, 1단계에서 사용자의 순위를 매긴 것과 같은 방식으로 USD 기준 정가 지출을 팀에 귀속시킬 수 있습니다. DBU 사용을 달러로 환산하려면 가입하세요 system.billing.list_prices :

SELECT
  u.custom_tags['team'] AS team,
  SUM(u.usage_quantity * lp.pricing.effective_list.default) AS list_cost_usd
FROM system.billing.usage u
JOIN system.billing.list_prices lp
  ON  u.sku_name   = lp.sku_name
  AND u.cloud      = lp.cloud
  AND u.usage_unit = lp.usage_unit
  AND u.usage_end_time >= lp.price_start_time
  AND (lp.price_end_time IS NULL OR u.usage_end_time < lp.price_end_time)
WHERE u.billing_origin_product = 'MODEL_SERVING'
  AND u.usage_metadata.ai_gateway.endpoint_name IS NOT NULL
  AND u.custom_tags['team'] IS NOT NULL
  AND u.usage_unit = 'DBU'
  AND lp.currency_code = 'USD'
  AND u.usage_date >= current_date() - INTERVAL 30 DAYS
GROUP BY team
ORDER BY list_cost_usd DESC;

외부 모델

외부 모델의 경우, system.ai_gateway.external_model_spend 이미 예상 비용을 USD 단위로 기록하고 custom_tags서비스 태그와 요청 태그를 모두 포함하고 있어, 프로젝트 또는 팀별로 서비스 간 지출을 그룹화 custom_tags.request_tags 할 수 있습니다:

SELECT
  custom_tags.request_tags['team'] AS team,
  SUM(usage_quantity) AS estimated_provider_cost_usd
FROM system.ai_gateway.external_model_spend
WHERE custom_tags.request_tags['team'] IS NOT NULL
  AND usage_date >= current_date() - INTERVAL 30 DAYS
GROUP BY team
ORDER BY estimated_provider_cost_usd DESC;

5단계: 팀 또는 프로젝트별 토큰당 비용 분석

Tip

지니 코드 (에이전트 모드)는 이 작업을 수행할 수 있습니다. 다음 예제 프롬프트를 사용해 보세요.

Query system.billing.usage and system.ai_gateway.usage for the past 30 days to show list-price USD per million tokens by model service, destination model, and the 'team' service tag. Convert DBUs to dollars using system.billing.list_prices at the price effective for each record, and join the two tables on usage date.

총 지출은 예산이 어디로 갔는지를 알려주지만, 공정한 가격을 지불하고 있는지 여부는 알려주지 않습니다. 추론 지출을 100만 토큰당 비용으로 추적하면 목적지 모델을 비교하거나, 라우팅 변경 후 회귀를 발견하거나, 트래픽을 더 저렴한 모델로 옮기는 것을 정당화할 수 있습니다. 비용 테이블을 모델 서비스, 대상 모델, 팀을 기준으로 system.ai_gateway.usage에 조인하세요. 두 탭 모두 서비스 태그별로 team 그룹화되어 결과가 3단계와 일치합니다:

Databricks 제공 모델

전체 기간 동안 리스트 프라이스 지출과 토큰을 집계한 후, 모델 서비스, 목적지 모델, 팀에 합류하세요. DBU 사용을 달러로 환산하려면 가입하세요 system.billing.list_prices :

WITH cost AS (
  SELECT
    u.usage_metadata.ai_gateway.endpoint_name AS endpoint_name,
    u.usage_metadata.ai_gateway.destination_model AS destination_model,
    u.custom_tags['team'] AS team,
    SUM(u.usage_quantity * lp.pricing.effective_list.default) AS list_cost_usd
  FROM system.billing.usage u
  JOIN system.billing.list_prices lp
    ON  u.sku_name   = lp.sku_name
    AND u.cloud      = lp.cloud
    AND u.usage_unit = lp.usage_unit
    AND u.usage_end_time >= lp.price_start_time
    AND (lp.price_end_time IS NULL OR u.usage_end_time < lp.price_end_time)
  WHERE u.billing_origin_product = 'MODEL_SERVING'
    AND u.usage_metadata.ai_gateway.endpoint_name IS NOT NULL
    AND u.custom_tags['team'] IS NOT NULL
    AND u.usage_unit = 'DBU'
    AND lp.currency_code = 'USD'
    AND u.usage_date >= current_date() - INTERVAL 30 DAYS
  GROUP BY ALL
),
tokens AS (
  SELECT
    endpoint_name,
    destination_model,
    endpoint_tags['team'] AS team,
    SUM(total_tokens) AS total_tokens
  FROM system.ai_gateway.usage
  WHERE endpoint_tags['team'] IS NOT NULL
    AND endpoint_name IS NOT NULL
    AND event_time >= current_timestamp() - INTERVAL 30 DAYS
  GROUP BY ALL
)
SELECT
  c.endpoint_name,
  c.destination_model,
  c.team,
  c.list_cost_usd,
  t.total_tokens,
  1000000 * c.list_cost_usd / NULLIF(t.total_tokens, 0) AS list_cost_usd_per_1m_tokens
FROM cost c
JOIN tokens t
  ON  c.endpoint_name     = t.endpoint_name
  AND c.destination_model = t.destination_model
  AND c.team              = t.team
ORDER BY list_cost_usd_per_1m_tokens DESC;

외부 모델

전체 창 동안 지출과 토큰을 집계한 후, 모델 제공자 서비스, 목적지 모델, 팀에 참여하세요. 두 테이블 모두 동일한 요청을 포함하므로, 주기 단위 총합은 조인에 시간 키가 필요하지 않습니다:

WITH spend AS (
  SELECT
    usage_metadata.endpoint_name AS endpoint_name,
    usage_metadata.model AS destination_model,
    custom_tags.endpoint_tags['team'] AS team,
    SUM(usage_quantity) AS estimated_provider_cost_usd
  FROM system.ai_gateway.external_model_spend
  WHERE custom_tags.endpoint_tags['team'] IS NOT NULL
    AND usage_date >= current_date() - INTERVAL 30 DAYS
  GROUP BY ALL
),
tokens AS (
  SELECT
    endpoint_name,
    destination_model,
    endpoint_tags['team'] AS team,
    SUM(total_tokens) AS total_tokens
  FROM system.ai_gateway.usage
  WHERE endpoint_tags['team'] IS NOT NULL
    AND destination_model IS NOT NULL
    AND event_time >= current_timestamp() - INTERVAL 30 DAYS
  GROUP BY ALL
)
SELECT
  s.endpoint_name,
  s.destination_model,
  s.team,
  s.estimated_provider_cost_usd,
  t.total_tokens,
  1000000 * s.estimated_provider_cost_usd / NULLIF(t.total_tokens, 0) AS estimated_cost_usd_per_1m_tokens
FROM spend s
JOIN tokens t
  ON  s.endpoint_name     = t.endpoint_name
  AND s.destination_model = t.destination_model
  AND s.team              = t.team
ORDER BY estimated_cost_usd_per_1m_tokens DESC;

팀 귀속을 위해 요청 태그를 사용하는 경우, 토큰 롤업에서 custom_tags.endpoint_tags['team']을(를) custom_tags.request_tags['team']으로 바꾸고 endpoint_tags['team']을(를) request_tags['team']으로 바꾸세요.

메모

Unity Gateway는 1 MiB 이상의 비스트리밍, 비임베딩 응답에 대해 토큰 사용을 기록하지 않기 때문에, 그런 응답이 흔한 곳에서는 토큰당 비용이 높을 수 있습니다. 관련 없는 업무량 사이가 아니라 업무량 내 요금을 비교하세요.

다음 단계