Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.
Contoh API batas tarif
Contoh berikut menunjukkan cara mengelola batas tarif menggunakan AWS CLI dan AWS Python SDK (Boto3).
Buat batas permintaan per target per detik
Contoh berikut membuat batas laju yang mengontrol permintaan per detik berdasarkan per target. Target tertentu mendapatkan 100 RPS, dan semua target lainnya masing-masing mendapatkan bucket 10 RPS mereka sendiri.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["targetName"]' \ --description "Per-target RPS limit" \ --entries '[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 100, "period": "second" } ] }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 10, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["targetName"], description="Per-target RPS limit", entries=[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 100, "period": "second", } ], }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 10, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
Buat batas permintaan per penelepon per menit
Contoh berikut membuat batas tarif berdasarkan klaim JWT sub penelepon. Pengguna premium mendapatkan 300 RPM, dan semua pengguna lain mendapatkan 60 RPM.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["$.context.jwt.sub"]' \ --description "Per-caller RPM by subscription tier" \ --entries '[ { "dimensions": {"$.context.jwt.sub": "premium-user-001"}, "requests": [ { "rate": 300, "period": "minute" } ] }, { "dimensions": {"$.context.jwt.sub": "premium-user-002"}, "requests": [ { "rate": 300, "period": "minute" } ] }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 60, "period": "minute" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["$.context.jwt.sub"], description="Per-caller RPM by subscription tier", entries=[ { "dimensions": {"$.context.jwt.sub": "premium-user-001"}, "requests": [ { "rate": 300, "period": "minute", } ], }, { "dimensions": {"$.context.jwt.sub": "premium-user-002"}, "requests": [ { "rate": 300, "period": "minute", } ], }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 60, "period": "minute", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
Buat batas multi-dimensi dengan token
Contoh berikut membuat batas tarif dengan kunci tiga dimensi yang membatasi permintaan dan token per menit. Setiap penelepon mendapatkan anggaran mereka sendiri yang dicakup untuk target dan model tertentu.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["targetName", "qualifiedModelId", "$.context.jwt.sub"]' \ --description "Per-caller token and request budget per target and model" \ --entries '[ { "dimensions": {"targetName": "my-inference-target", "qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "minute" } ], "tokens": [ { "rate": 50000, "period": "minute" } ] }, { "dimensions": {"targetName": "*", "qualifiedModelId": "*", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 30, "period": "minute" } ], "tokens": [ { "rate": 10000, "period": "minute" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["targetName", "qualifiedModelId", "$.context.jwt.sub"], description="Per-caller token and request budget per target and model", entries=[ { "dimensions": {"targetName": "my-inference-target", "qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "minute", } ], "tokens": [ { "rate": 50000, "period": "minute", } ], }, { "dimensions": {"targetName": "*", "qualifiedModelId": "*", "$.context.jwt.sub": "*"}, "requests": [ { "rate": 30, "period": "minute", } ], "tokens": [ { "rate": 10000, "period": "minute", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
Buat batas kecepatan koneksi
Contoh berikut membuat batas kecepatan koneksi per model. Ini membatasi jumlah permintaan dalam penerbangan bersamaan untuk setiap model, yang berguna untuk melindungi target yang memiliki kapasitas konkurensi terbatas.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["qualifiedModelId"]' \ --description "Connection rate limit per model" \ --entries '[ { "dimensions": {"qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0"}, "connections": [ { "rate": 50, "period": "second" } ] }, { "dimensions": {"qualifiedModelId": "*"}, "connections": [ { "rate": 20, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["qualifiedModelId"], description="Connection rate limit per model", entries=[ { "dimensions": {"qualifiedModelId": "anthropic.claude-3-sonnet-20240229-v1:0"}, "connections": [ { "rate": 50, "period": "second", } ], }, { "dimensions": {"qualifiedModelId": "*"}, "connections": [ { "rate": 20, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
Blokir penelepon dengan tarif nol
Contoh berikut memblokir pemanggil tertentu dengan mengatur tarifnya ke 0. Ini menolak semua permintaan dari penelepon yang diblokir setelah perubahan menyebar (hingga 30 detik).
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control create-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --dimension-keys '["$.context.jwt.sub"]' \ --description "Block abusive caller" \ --entries '[ { "dimensions": {"$.context.jwt.sub": "blocked-user-789"}, "requests": [ { "rate": 0, "period": "second" } ] }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.create_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", dimensionKeys=["$.context.jwt.sub"], description="Block abusive caller", entries=[ { "dimensions": {"$.context.jwt.sub": "blocked-user-789"}, "requests": [ { "rate": 0, "period": "second", } ], }, { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ { "rate": 100, "period": "second", } ], }, ], ) print(f"Rate Limit ID: {response['rateLimitId']}")
-
Dapatkan batas tarif
Contoh berikut mengambil rincian batas tarif tertentu.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control get-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.get_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", ) print(f"Status: {response['status']}") print(f"Dimension Keys: {response['dimensionKeys']}") print(f"Entries: {len(response['entries'])}")
-
Memperbarui batas tarif
Contoh berikut memperbarui entri batas tarif yang ada untuk meningkatkan tarif untuk target tertentu.
catatan
dimensionKeysBidang ini tidak berubah setelah penciptaan. Untuk mengubah kunci dimensi, hapus batas tarif dan buat yang baru.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control update-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456 \ --description "Updated per-target RPS limit" \ --entries '[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 200, "period": "second" } ] }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 20, "period": "second" } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.update_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", description="Updated per-target RPS limit", entries=[ { "dimensions": {"targetName": "my-high-traffic-target"}, "requests": [ { "rate": 200, "period": "second", } ], }, { "dimensions": {"targetName": "*"}, "requests": [ { "rate": 20, "period": "second", } ], }, ], ) print(f"Status: {response['status']}")
-
Daftar batas tarif
Contoh berikut mencantumkan semua batas tarif untuk gateway.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control list-gateway-rate-limits \ --gateway-identifier my-gateway-abc1234567
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") paginator = client.get_paginator("list_gateway_rate_limits") for page in paginator.paginate(gatewayIdentifier="my-gateway-abc1234567"): for rate_limit in page["rateLimits"]: print( f"ID: {rate_limit['rateLimitId']}, " f"Status: {rate_limit['status']}, " f"Dimensions: {rate_limit['dimensionKeys']}" )
-
catatan
Hasil mungkin dipaginasi. Gunakan nextToken nilai dari respons untuk mengambil halaman tambahan, atau gunakan paginator Boto3 seperti yang ditunjukkan di atas.
Menghapus batas tarif
Contoh berikut menghapus batas tarif dari gateway.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control delete-gateway-rate-limit \ --gateway-identifier my-gateway-abc1234567 \ --rate-limit-id rl-abc123def456
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.delete_gateway_rate_limit( gatewayIdentifier="my-gateway-abc1234567", rateLimitId="rl-abc123def456", ) print(f"Status: {response['status']}")
-
Batas tarif batch put
Contoh berikut membuat atau memperbarui beberapa batas tarif dalam satu panggilan. Batch put menggunakan semantik upsert - jika batas laju dengan kunci dimensi yang sama ada, itu diperbarui; jika tidak, batas tarif baru dibuat.
catatan
Batch put adalah idempoten. Anda dapat mencoba kembali panggilan yang gagal dengan aman tanpa membuat batas tarif duplikat.
contoh
- AWS CLI
-
-
Jalankan perintah berikut:
aws bedrock-agentcore-control batch-put-gateway-rate-limits \ --gateway-identifier my-gateway-abc1234567 \ --rate-limits '[ { "dimensionKeys": ["targetName"], "description": "Per-target RPS", "entries": [ { "dimensions": {"targetName": "*"}, "requests": [{"rate": 50, "period": "second"}] } ] }, { "dimensionKeys": ["$.context.jwt.sub"], "description": "Per-caller RPM", "entries": [ { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [{"rate": 120, "period": "minute"}] } ] } ]'
-
- AWS Python SDK (Boto3)
-
-
import boto3 client = boto3.client("bedrock-agentcore-control", region_name="us-west-2") response = client.batch_put_gateway_rate_limits( gatewayIdentifier="my-gateway-abc1234567", rateLimits=[ { "dimensionKeys": ["targetName"], "description": "Per-target RPS", "entries": [ { "dimensions": {"targetName": "*"}, "requests": [ {"rate": 50, "period": "second"} ], } ], }, { "dimensionKeys": ["$.context.jwt.sub"], "description": "Per-caller RPM", "entries": [ { "dimensions": {"$.context.jwt.sub": "*"}, "requests": [ {"rate": 120, "period": "minute"} ], } ], }, ], ) for result in response["rateLimits"]: print(f"ID: {result['rateLimitId']}, Status: {result['status']}")
-