🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ai-gateway): attribute provider connections (#17340)
Tobias Wochingerd2204d4a1761
diff --git a/ai-gateway/src/resolution/contracts.rs b/ai-gateway/src/resolution/contracts.rsindex ac96be0a6f..94311d3afb 100644--- a/ai-gateway/src/resolution/contracts.rs+++ b/ai-gateway/src/resolution/contracts.rs@@ -79,6 +79,7 @@ pub struct Attribution {project_id: String,key_id: String,key_metadata: BTreeMap<String, MetadataValue>,+ provider_connection_id: String,}impl Attribution {@@ -94,6 +95,9 @@ impl Attribution {pub fn key_metadata(&self) -> &BTreeMap<String, MetadataValue> {&self.key_metadata}+ pub fn provider_connection_id(&self) -> &str {+ &self.provider_connection_id+ }}#[derive(Deserialize)]@@ -176,6 +180,7 @@ pub(super) fn decode(&attribution.organization_id,&attribution.project_id,&attribution.key_id,+ &attribution.provider_connection_id,].iter().any(|value| value.trim().is_empty())diff --git a/ai-gateway/src/resolution/tests.rs b/ai-gateway/src/resolution/tests.rsindex 5539c923de..0873822f96 100644--- a/ai-gateway/src/resolution/tests.rs+++ b/ai-gateway/src/resolution/tests.rs@@ -97,7 +97,8 @@ fn success(project: &str, provider_token: &str) -> Value {"organization_id": "org-1","project_id": project,"key_id": "key-1",- "key_metadata": {"customer": "private-customer-label", "enabled": true, "number": 42}+ "key_metadata": {"customer": "private-customer-label", "enabled": true, "number": 42},+ "provider_connection_id": "connection-1"},"ingestion_mode": "usage","ingestion": {"access_token": "private-ingestion-token", "token_type": "Bearer", "expires_at": NOW + 300}@@ -129,6 +130,10 @@ async fn signs_the_exact_key_and_sends_only_the_api_format() {"private-provider-token");assert_eq!(context.attribution().project_id(), "project-1");+ assert_eq!(+ context.attribution().provider_connection_id(),+ "connection-1"+ );assert_eq!(context.ingestion().access_token(),"private-ingestion-token"@@ -342,6 +347,7 @@ async fn rejects_incompatible_or_incomplete_execution_contexts() {("/connection/auth/token", json!("bad\r\nheader")),("/connection/id", json!("")),("/attribution/project_id", json!("")),+ ("/attribution/provider_connection_id", json!("")),("/attribution/key_metadata",json!({"nested": {"key": "value"}}),diff --git a/web/src/__e2e__/ai-gateway.gatewaye2e.ts b/web/src/__e2e__/ai-gateway.gatewaye2e.tsindex 58b66fb954..bfe73967da 100644--- a/web/src/__e2e__/ai-gateway.gatewaye2e.ts+++ b/web/src/__e2e__/ai-gateway.gatewaye2e.ts@@ -311,7 +311,7 @@ describe("AI gateway live end-to-end", () => {async ({ provider, apiFormat, baseUrl, authType }) => {await withGatewayApiKey({ provider, apiFormat },- async ({ secretKey, id: keyId }) => {+ async ({ secretKey, id: keyId, providerConnectionId }) => {const resolveBody = await gatewayControlPlaneRequest({path: RESOLVE_PATH,apiFormat,@@ -342,6 +342,7 @@ describe("AI gateway live end-to-end", () => {provider,apiFormat,},+ provider_connection_id: providerConnectionId,});expect(resolved.ingestion).toMatchObject({access_token: expect.stringMatching(/\S/),@@ -370,7 +371,11 @@ async function withGatewayApiKey(provider: GatewayProviderName;apiFormat: GatewayApiFormat;},- run: (key: { secretKey: string; id: string }) => Promise<void>,+ run: (key: {+ secretKey: string;+ id: string;+ providerConnectionId: string;+ }) => Promise<void>,) {const targetConnectionId = connectionIdsByProvider.get(input.provider);if (!targetConnectionId) {@@ -399,7 +404,11 @@ async function withGatewayApiKey(listedKeys.data.some(({ apiKey }) => apiKey.id === gatewayKey.id),).toBe(true);- await run({ secretKey: gatewayKey.secretKey, id: gatewayKey.id });+ await run({+ secretKey: gatewayKey.secretKey,+ id: gatewayKey.id,+ providerConnectionId: targetConnectionId,+ });} finally {await admin.caller.aiGateway.revokeApiKey({orgId: ORGANIZATION_ID,diff --git a/web/src/features/ai-gateway/server/provider/registry.ts b/web/src/features/ai-gateway/server/provider/registry.tsindex bab4aae129..e0e6f51c2d 100644--- a/web/src/features/ai-gateway/server/provider/registry.ts+++ b/web/src/features/ai-gateway/server/provider/registry.ts@@ -46,6 +46,7 @@ export const GatewayResolveResponseSchema = zproject_id: z.string(),key_id: z.string(),key_metadata: GatewayMetadataSchema,+ provider_connection_id: z.string(),}).strict(),ingestion_mode: z.enum(["usage", "full"]),diff --git a/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts b/web/src/features/ai-gateway/server/resolve/resolveService.servertest.tsindex 3806a72f25..001f5255d6 100644--- a/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts+++ b/web/src/features/ai-gateway/server/resolve/resolveService.servertest.ts@@ -107,6 +107,7 @@ describe("GatewayResolveService", () => {project_id: "project-1",key_id: "key-1",key_metadata: { team: "platform", project_id: "spoofed-project" },+ provider_connection_id: "connection-1",},ingestion_mode: "usage",ingestion: {@@ -133,6 +134,7 @@ describe("GatewayResolveService", () => {project_id: "project-1",key_id: "key-1",key_metadata: {},+ provider_connection_id: "connection-1",},});});diff --git a/web/src/features/ai-gateway/server/resolve/resolveService.ts b/web/src/features/ai-gateway/server/resolve/resolveService.tsindex 4a4c34890c..668c3a594e 100644--- a/web/src/features/ai-gateway/server/resolve/resolveService.ts+++ b/web/src/features/ai-gateway/server/resolve/resolveService.ts@@ -113,6 +113,7 @@ export class GatewayResolveService {project_id: context.ingestionProjectId,key_id: context.apiKeyId,key_metadata: context.keyMetadata,+ provider_connection_id: context.connection.id,},ingestion_mode: context.ingestionMode.toLowerCase() as "usage" | "full",ingestion: this.createIngestionResponse({