static_resources:
  listeners:
  - address:
      socket_address:
        address: 0.0.0.0
        port_value: 8080
    filter_chains:
    - filters:
      - name: envoy.filters.network.http_connection_manager
        typed_config:
          "@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
          codec_type: AUTO
          stat_prefix: ingress_http
          route_config:
            name: local_route
            virtual_hosts:
            - name: llm_service
              domains:
              - "*"
              routes:
              - match:
                  prefix: "/chat"
                route:
                  cluster: llm-cluster
          http_filters:
          - name: envoy.filters.http.sse_to_metadata
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.sse_to_metadata.v3.SseToMetadata
              response_rules:
                content_parser:
                  name: envoy.content_parsers.json
                  typed_config:
                    "@type": type.googleapis.com/envoy.extensions.content_parsers.json.v3.JsonContentParser
                    rules:
                    - rule:
                        selectors:
                        - key: "usage"
                        - key: "total_tokens"
                        on_present:
                          metadata_namespace: envoy.lb
                          key: tokens
                          type: NUMBER
                    - rule:
                        selectors:
                        - key: "model"
                        on_present:
                          metadata_namespace: envoy.lb
                          key: model_name
                          type: STRING
                      stop_processing_after_matches: 1
          - name: envoy.filters.http.router
            typed_config:
              "@type": type.googleapis.com/envoy.extensions.filters.http.router.v3.Router

  clusters:
  - name: llm-cluster
    type: STRICT_DNS
    lb_policy: ROUND_ROBIN
    load_assignment:
      cluster_name: llm-cluster
      endpoints:
      - lb_endpoints:
        - endpoint:
            address:
              socket_address:
                address: api.openai.com
                port_value: 443
    transport_socket:
      name: envoy.transport_sockets.tls
      typed_config:
        "@type": type.googleapis.com/envoy.extensions.transport_sockets.tls.v3.UpstreamTlsContext
        sni: api.openai.com
