Code Velocity
IA Empresarial

Gestió de costos d'IA: Projectes d'Amazon Bedrock per a l'atribució

·5 min de lectura·AWS·Font original
Compartir
Diagrama que mostra el flux d'atribució de costos dels Projectes d'Amazon Bedrock per gestionar les despeses d'IA en diferents càrregues de treball

A continuació, utilitzeu l'script de Python proporcionat per crear un projecte, assegurant-vos que la vostra regió d'AWS estigui configurada correctament i que la vostra clau API d'Amazon Bedrock estigui configurada com a variable d'entorn OPENAI_API_KEY.

import os
import requests

# Configuration
BASE_URL = "https://bedrock-mantle.<YOUR-REGION-HERE>.api.aws/v1"
API_KEY  = os.environ.get("OPENAI_API_KEY")  # Your Amazon Bedrock API key

def create_project(name: str, tags: dict) -> dict:
    """Create a Bedrock project with cost allocation tags."""
    response = requests.post(
        f"{BASE_URL}/organization/projects",
        headers={
            "Authorization": f"Bearer {API_KEY}",
            "Content-Type": "application/json"
        },
        json={"name": name, "tags": tags}
    )

    if response.status_code != 200:
        raise Exception(
            f"Failed to create project: {response.status_code} - {response.text}"
        )

    return response.json()

# Example: Create a production project with full tag taxonomy
project = create_project(
    name="CustomerChatbot-Prod",
    tags={
        "Application": "CustomerChatbot",
        "Environment": "Production",
        "Team":        "CustomerExperience",
        "CostCenter":  "CC-1001",
        "Owner":       "alice"
    }
)
print(f"Created project: {project['id']}")

Aquest script retornarà els detalls del projecte, incloent el seu id únic (per exemple, proj_123) i l'ARN. Guardeu aquest id ja que serà crucial per associar les vostres sol·licituds d'inferència. Podeu crear fins a 1.000 projectes per compte d'AWS, oferint una gran flexibilitat fins i tot per a les organitzacions més grans.

Associació de Sol·licituds d'Inferència

Un cop creat el vostre projecte, integreu el seu ID a les vostres trucades a l'API de Bedrock. Per exemple, utilitzant la Responses API:

from openai import OpenAI

client = OpenAI(
    base_url="https://bedrock-mantle.<YOUR-REGION-HERE>.api.aws/v1",
    project="<YOUR-PROJECT-ID>", # ID returned when you created the project
)
response = client.responses.create(
    model="openai.gpt-oss-120b",
    input="Summarize the key findings from our Q4 earnings report."
)
print(response.output_text)

En incloure constantment el paràmetre project, assegureu una atribució precisa de costos per a cada inferència. Per a aplicacions de Bedrock més avançades, considereu com això s'integra amb estratègies més àmplies, com la construcció d'un motor de proves A/B basat en IA utilitzant Amazon Bedrock.

Activació i Anàlisi dels Vostres Costos d'IA a AWS

El pas final per habilitar una visibilitat completa dels costos és activar les vostres etiquetes de projecte personalitzades com a etiquetes d'assignació de costos a la consola de facturació d'AWS. Aquesta és una configuració única que indica a AWS que incorpori aquestes etiquetes als vostres informes de facturació detallats.

Activació d'Etiquetes d'Assignació de Costos

Navegueu a la consola d'AWS Billing and Cost Management i seguiu les instruccions per activar les vostres etiquetes personalitzades. Es recomana fer-ho tan aviat com es creï el vostre primer projecte per evitar llacunes en les vostres dades de costos. Tingueu en compte que pot trigar fins a 24 hores perquè aquestes etiquetes es propaguin completament i apareguin a AWS Cost Explorer i AWS Data Exports.

Visualització dels Costos del Projecte a AWS Cost Explorer

Un cop activat, podeu aprofitar AWS Cost Explorer per visualitzar i analitzar la vostra despesa en Amazon Bedrock amb un nivell de detall sense precedents. Podeu filtrar els vostres costos per Service (Amazon Bedrock) i després agrupar-los per les vostres etiquetes d'assignació de costos personalitzades, com ara 'Aplicació', 'Entorn' o 'Centre de costos'. Això us permet:

  • Identificar els Factors de Cost: Identificar ràpidament quines aplicacions o entorns estan consumint la majoria de recursos d'IA generativa.
  • Realitzar Càrrecs Interns: Generar informes precisos per a models de càrrec intern, assegurant que els departaments facturin de manera justa el seu ús d'IA.
  • Optimitzar la Despesa: Detectar àrees d'ineficiència, com ara models cars que s'utilitzen en entorns de desenvolupament no crítics, i prendre decisions informades per optimitzar l'assignació de recursos.
  • Preveure i Pressupostar: Millorar la precisió de les previsions de despesa futura en IA analitzant dades històriques desglossades per càrregues de treball específiques.

En adoptar els Projectes d'Amazon Bedrock i una estratègia d'etiquetatge disciplinada, les organitzacions poden transformar les despeses d'IA nebuloses en coneixements transparents i accionables. Això no només dona suport a una millor governança financera, sinó que també fomenta una cultura de consciència dels costos, permetent als equips escalar les seves iniciatives d'IA generativa de manera responsable i efectiva. Aquest control detallat sobre els recursos també és clau per integrar noves capacitats com Amazon Bedrock AgentCore de manera eficient.

Preguntes freqüents

What are Amazon Bedrock Projects and how do they enhance AI cost management?
Amazon Bedrock Projects provide a logical boundary within the Amazon Bedrock service to represent specific AI workloads, such as applications, environments, or experiments. By associating inference requests with a project ID and attaching resource tags, organizations can gain granular visibility into their generative AI spending. This allows for precise cost attribution to individual teams, departments, or applications, facilitating accurate chargebacks, identifying cost spikes, and informing strategic optimization decisions, thereby enhancing overall financial governance and resource allocation for large-scale AI deployments.
Why is a robust tagging strategy crucial for effective cost attribution with Bedrock Projects?
A robust tagging strategy is crucial because the tags attached to Amazon Bedrock Projects become the primary dimensions for filtering and grouping cost data in AWS Cost Explorer and AWS Data Exports. By systematically tagging projects with attributes like 'Application,' 'Environment,' 'Team,' and 'CostCenter,' organizations can create a comprehensive taxonomy that mirrors their internal structure. This structured approach enables deep dives into spending patterns, helps identify high-cost areas, supports cross-departmental chargebacks, and ensures that financial reporting accurately reflects resource consumption by specific AI workloads, making cost analysis more actionable and transparent.
How do I activate cost allocation tags for Amazon Bedrock Projects in AWS Billing?
After defining your tagging strategy and creating projects with associated tags in Amazon Bedrock, you must activate these tags as cost allocation tags within the AWS Billing and Cost Management console. This crucial, one-time setup step ensures that the tags attached to your Bedrock Projects are recognized by the AWS billing pipeline. Once activated, it can take up to 24 hours for the tags to propagate and for cost data to become visible and filterable in tools like AWS Cost Explorer and AWS Data Exports. Activating these tags promptly after your initial project setup prevents gaps in your cost visibility and ensures continuous, accurate reporting.
Which Amazon Bedrock APIs support cost attribution through Project IDs?
Currently, Amazon Bedrock Projects support cost attribution via Project IDs for inference requests made through the OpenAI-compatible APIs, specifically the Responses API and the Chat Completions API. When making API calls using these endpoints, developers should include the designated Project ID to ensure that the associated costs are accurately attributed to the correct workload. It is a best practice to always explicitly specify a Project ID in API calls to avoid costs being automatically associated with the default project in your AWS account, which can hinder granular cost analysis and management efforts.
What are the benefits of using Amazon Bedrock Projects for large enterprises?
For large enterprises, Amazon Bedrock Projects offer significant benefits by providing a standardized, scalable mechanism for managing and optimizing generative AI costs. They enable granular visibility into AI spending across diverse teams, applications, and environments, supporting precise financial forecasting and budgeting. This capability is vital for complex organizational structures requiring chargebacks or detailed departmental cost allocation. Furthermore, it empowers businesses to identify inefficient workloads, optimize model usage, and make data-driven decisions to reduce overall AI infrastructure expenses, aligning technology investments with business value and ensuring responsible AI scaling.

Manteniu-vos al dia

Rebeu les últimes notícies d'IA al correu.

Compartir