Introducing a new way to review your PRs.

Read the announcement

thomaspoignant / go-feature-flag

GO Feature Flag is a simple, complete and lightweight self-hosted cloud native feature flag solution 100% Open Source — built on OpenFeature 🎛️

View on GitHub

18 documents · Updated Nov 23, 2026

docs / relay-proxy-evaluation-api

Relay proxy evaluation API

The relay proxy evaluation API lets remote clients ask GO Feature Flag for one or more flag values. It accepts a client evaluation context, selects the flag set linked to the request credentials, and returns an evaluation result or a clear error. It also accepts evaluation data from providers, validates flag files for administrators, and pushes flag-change notices to connected clients. For the wider service model, see Relay proxy service; for setup and runtime concerns, see Relay proxy configuration and deployment.

API surface

The API exposes evaluation, administration, data collection, and notification contracts. Evaluation routes use client credentials, while administration routes use a separate admin credential contract.

Route families

The route groups apply the required authentication before they call a handler. The main client and operator paths are:

CapabilityMethod and pathAuth scopeClient result
GO Feature Flag single evaluationPOST /v1/feature/{flag_key}/evalEvaluationOne flag result. A configured default value remains available when evaluation fails.
GO Feature Flag bulk evaluationPOST /v1/allflagsEvaluationA snapshot of all flags for a context.
GO Feature Flag flag-change checkGET /v1/flag/changeEvaluationThe current flag-change state for a client.
GO Feature Flag flag configurationPOST /v1/flag/configurationEvaluationFlag configuration data for a client.
OFREP single evaluationPOST /ofrep/v1/evaluate/flags/{flag_key}EvaluationOne OFREP result or an OFREP error response.
OFREP bulk evaluationPOST /ofrep/v1/evaluate/flagsEvaluationA list of requested flags, or all available flags when no list is supplied.
OpenFeature manifestGET /openfeature/v0/manifestEvaluationThe current flag manifest and a read capability header.
Cached event collectionPOST /v1/data/collectorEvaluationThe number of event records accepted for processing.
Retriever refreshPOST /admin/v1/retriever/refreshAdminA request to refresh the flag source.
Flag file validationPOST /admin/v1/flags/validateAdminA validation result without changing served flags.

When the proxy runs as an AWS Lambda handler, the same HTTP behavior is adapted for API Gateway v1, API Gateway v2, or an Application Load Balancer event. An optional base path is removed before route matching, so clients can call the API below a gateway prefix. References: cmd/…/lambda_handler_test.go• L21-131, cmd/…/lambda_handler_test.go• L133-232, cmd/…/handlers_test.go• L23-68, cmd/…/retriever_refresh_test.go• L20-70

The route layer applies ETag handling to stable bulk flag responses. A client can therefore avoid downloading an unchanged GO Feature Flag or OFREP bulk result when it sends a matching If-None-Match value. The API also applies CORS handling to browser requests. A browser preflight can complete before API-key authentication, while requests without an Origin header do not receive a CORS response header. References: cmd/…/routes_goff.go• L10-45, cmd/…/routes_ofrep.go• L9-26, cmd/…/server.go• L68-100, cmd/…/routes_cors_test.go• L85-151

Monitoring endpoints

The proxy exposes health, service information, and metrics endpoints for operators and platform checks. These endpoints use the main API listener unless a monitoring port is configured, in which case the proxy serves them on a separate monitoring listener; profiling endpoints are available only when debug mode or profiling is enabled. Both listeners use the same CORS and version-header behavior. References: cmd/…/routes_monitoring.go• L14-53, cmd/…/server.go• L84-100, cmd/…/server_lifecycle.go• L84-127, cmd/…/routes_monitoring_test.go• L22-134, cmd/…/README.md• L22-55

Client authentication

The evaluation routes use the configured user API-key check. Clients can send the key in X-API-Key, or in Authorization; the latter may use the Bearer <key> form. The same key is later used to select the flag set, so authentication and evaluation routing must use the same credential.

If authentication is disabled in the proxy configuration, the user route middleware allows the request through and the proxy uses its default flag set. Admin routes remain protected by the admin key check, even when user authentication is disabled. In flag-set mode, a missing or unknown evaluation key cannot select a flag set and the handler returns a bad-request error. References: cmd/…/server.go• L131-175, cmd/…/routes_admin.go• L8-16, cmd/…/key_auth_extended.go• L51-77, cmd/…/echo_helper.go• L12-41, cmd/…/flagset_manager.go• L205-228, cmd/…/server_test.go• L378-450

Request-body handling

Debug logging can record request bodies to help diagnose client requests, but it does not record Swagger requests or flag files sent to the validation endpoint. Bodies that are logged are limited to 8 KiB, which prevents large requests from filling the log. References: cmd/…/body_dump_handler.go• L12-53, cmd/…/server.go• L68-76, cmd/…/body_dump_handler_test.go• L16-72

Evaluation flow

Every evaluation follows the same high-level path: validate the request, turn its context into the internal evaluation context, resolve the flag set, and ask the GO Feature Flag client for a value. The handler records evaluation metrics and tracing around this work, but the flag rules and value choice remain the responsibility of the evaluation service.

flowchart LR
    A[Client request] --> B[Route authentication]
    B --> C[Decode and validate context]
    C --> D[Resolve flag set from API key]
    D --> E[Evaluate flag or flag set]
    E --> F[Build client response]
    E --> G[Create evaluation data when tracking applies]

GO Feature Flag evaluation

The GO Feature Flag request can carry the newer evaluationContext object. The older user object remains accepted for compatibility. The handler requires one of these inputs and uses defaultValue as the safe result when the flag cannot produce a normal variation.

The single-flag response exposes the selected value together with the variation name, flag version, reason, error code, tracking state, and failure state. A failed result still uses HTTP 200 because clients can read failed and use the returned default value. The bulk endpoint returns the flag snapshot with its validity state and the per-flag results. A bulk request can still evaluate flags that do not need a targeting key; only evaluations that need bucketing report a per-flag error. References: cmd/…/flag_eval.go• L29-101, cmd/…/all_flags.go• L29-90, cmd/…/utils.go• L13-54, cmd/…/user_request.go• L3-14, cmd/…/eval_docs.go• L3-20, cmd/…/all_flags_test.go• L68-112, cmd/…/all_flags_test.go• L221-244

OFREP evaluation

The OFREP request has one context map. The map may be empty, and targetingKey is optional until a flag rule needs it for bucketing. A single evaluation returns key, value, reason, variant, and optional metadata.

The bulk endpoint evaluates the flag names in the context when the client provides a flag list. Without that list, it evaluates all available flags. It returns flags in key order. A flag-level error in the bulk result has no value and carries errorCode and errorDetails; a single-flag error uses HTTP 400 for a bad evaluation and HTTP 404 when the flag does not exist. The handler returns JSON error responses for malformed input instead of a server error. References: cmd/…/evaluate.go• L34-132, cmd/…/evaluate.go• L135-223, cmd/…/ofrep_requests.go• L3-6, cmd/…/ofrep_success_response.go• L3-9, cmd/…/ofrep_bulk_success_response.go• L3-11, cmd/…/ofrep_error_response.go• L9-17, cmd/…/evaluate_test.go• L28-114, cmd/…/evaluate_test.go• L274-399, cmd/…/evaluate_fuzz_test.go• L24-65

Flag-set routing

The flag-set manager is the boundary between HTTP requests and a running GO Feature Flag client. In default mode, all requests use one default flag set. In flag-set mode, the API key maps to one named flag set, which keeps evaluation data and flag-change notifications associated with the right client configuration.

The manager can update API-key routing while the proxy runs. It can add or remove named flag sets and change their keys, but it keeps the current mode and rejects invalid or unsupported changes. An evaluation request therefore does not select a flag set from the request body; it selects the set from the authenticated request key. References: cmd/…/flagset_manager.go• L30-46, cmd/…/flagset_manager.go• L205-245, cmd/…/server.go• L102-139, cmd/…/flagset_manager_test.go• L643-724, cmd/…/flagset_manager_test.go• L1000-1272, cmd/…/flagset_manager_test.go• L1512-1792

Flag file validation

The admin validation endpoint checks a submitted flag file before an operator loads it. It uses the same flag rules as the goff lint command, but it does not load the file or change the flags that the relay proxy serves.

The request format comes from Content-Type. JSON accepts bodies up to 1 MiB by default, while YAML and TOML accept bodies up to 64 KiB by default; each limit can be configured. A valid file returns HTTP 200 with valid: true. A parsed file with invalid flags returns HTTP 422 with one flag and message per validation error. Unsupported media types, unreadable or malformed bodies, and bodies above the selected limit return HTTP 415, 400, or 413 as appropriate. References: cmd/…/validate_flags.go• L25-69, cmd/…/validate_flags.go• L70-156, cmd/…/config_endpoints.go• L56-109, cmd/…/validate_flags_test.go• L101-255

Evaluation data collection

The collector endpoint receives events that provider clients held in a local cache. It lets those clients send feature-evaluation and tracking events in one request instead of losing data when a cached evaluation does not call the proxy in real time.

Event ingestion

The request contains an events list and optional meta data. Each event is classified by its kind: tracking events go to tracking export, while other events become feature-evaluation events. The optional metadata applies to feature events, and cached feature events use PROVIDER_CACHE as their source when the source is absent.

The handler accepts a batch and returns ingestedContentCount equal to the number of records in the request. It converts timestamps that look like milliseconds to seconds before the event reaches the configured exporter. A malformed individual event is logged and skipped so one bad record does not stop the rest of the batch. References: cmd/…/collect_eval_data.go• L42-135, cmd/…/collect_eval_data.go• L138-186, cmd/…/collect_eval_data_request.go• L7-15, cmd/…/collect_eval_data_response.go• L3-7, exporter/feature_event.go• L44-86, cmd/…/collect_eval_data_test.go• L27-235, cmd/…/collect_eval_data_test.go• L373-494

Export handoff

The collector does not choose a destination for each event. It resolves the request to the correct flag set and hands the converted events to that flag set’s configured data exporters. This keeps live evaluation data and provider-cache data on the same export path after they enter the proxy.

Large batches observe request cancellation between records. A cancelled request can therefore stop after partial processing and return an error instead of claiming that the full batch completed. References: cmd/…/collect_eval_data.go• L77-135, cmd/…/collect_eval_data.go• L84-102, cmd/…/gofeatureflag_client.go• L40-100, cmd/…/collect_eval_data_test.go• L332-371

Flag-change notifications

The proxy exposes long-lived notification connections for clients that need flag changes without polling. A flag change is represented as a DiffCache with added, deleted, and updated flag definitions. The running flag-set client sends that diff to the proxy notification service after its flag data changes.

Streaming transports

Clients can choose WebSocket or Server-Sent Events (SSE). WebSocket broadcasts a diff to connected clients for the relevant flag set. SSE routes the diff to the stream for the flag set linked to the connection’s API key, so a client does not receive changes from another flag set.

The current paths are GET /stream/v1/ws/flag/change and GET /stream/v1/sse/flag/change. The older GET /ws/v1/flag/change path remains a deprecated alias for WebSocket clients and advertises the current path through deprecation and successor headers. Streaming authentication uses the apiKey query parameter rather than the evaluation header. In default flag-set mode the SSE connection does not need this parameter; in flag-set mode it is required to select the stream. Clients and intermediaries must treat the full SSE URL as sensitive because it includes that credential. References: cmd/…/routes_stream.go• L9-29, cmd/…/routes_stream_test.go• L22-61, cmd/…/stream_authorizer.go• L8-19, cmd/…/sse_flag_change.go• L34-85, cmd/…/sse_flag_change_test.go• L161-221, cmd/…/ws_flag_change.go• L66-128, cmd/…/ws_flag_change_test.go• L347-485

Notification delivery

Each running flag set receives a notification adapter during service setup. The WebSocket adapter sends the diff to connected clients for that flag set. The SSE adapter publishes it only to the named flag-set stream. This relationship makes the API key-to-flag-set mapping part of the notification contract, not only part of evaluation.

An SSE client receives an event: message event with an OFREP event payload. A refetchEvaluation event tells the provider to fetch its evaluations again. Connection and heartbeat comments do not represent flag changes. SSE connections close when the server shuts down. WebSocket connections use keep-alive messages and are removed when a write or read fails. Concurrent keep-alive and change messages are serialized for each WebSocket connection. During shutdown, the proxy closes both stream services before it stops accepting HTTP requests. It closes the flag sets last so buffered evaluation data can flush after request handling ends. References: cmd/…/notifier_websocket.go• L8-20, cmd/…/notifier_sse.go• L8-24, cmd/…/sse.go• L12-64, cmd/…/websocket.go• L16-83, notifier/diff_cache.go• L7-23, cmd/…/sse_flag_change.go• L34-45, cmd/…/sse_flag_change_test.go• L103-157, cmd/…/ws_flag_change.go• L16-37, cmd/…/ws_flag_change_internal_test.go• L45-165, cmd/…/ws_flag_change_test.go• L199-292, cmd/…/main.go• L104-131, cmd/…/main.go• L135-152, cmd/…/main_test.go• L24-35

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the route path, authentication group, handler method, and generated API description aligned for GO Feature Flag, OFREP, and admin endpoints.
  • If a request or response field changes, update the matching model, error shape, provider contract, and OpenAPI documentation together.
  • Preserve the difference between GO Feature Flag fallback responses and OFREP HTTP error responses. Clients use these contracts differently.
  • If API-key routing changes, check evaluation selection and SSE and WebSocket stream selection together. A mismatch can expose the right flag value through the wrong notification stream.
  • If the validation endpoint changes, keep its admin-only access, content-type mapping, per-format size limits, non-mutating behavior, and 200/400/413/415/422 status contract aligned.
  • If collector event fields change, keep feature-event conversion, tracking-event conversion, timestamp units, and exporter schemas compatible.
  • If a stream path or credential source changes, update the deprecated WebSocket alias and all client-facing authorization behavior at the same time.
  • Keep the SSE event type, event name, heartbeat behavior, and advertised OFREP event-stream contract aligned when notification payloads change.
  • If monitoring routes change, keep their listener placement, CORS behavior, version header, and metrics, health, information, and profiling availability rules aligned.
  • If server startup or shutdown changes, keep the API listener, optional monitoring listener, long-lived streams, tracing service, and exporter flush order within the same lifecycle.
  • If runtime flag-set updates change, preserve atomic routing changes and reject invalid updates without replacing the last working configuration.
  • If Lambda base-path or event-adapter behavior changes, keep API Gateway v1, API Gateway v2, ALB, and direct HTTP route behavior consistent.
  • If manifest or retriever refresh contracts change, keep their client or operator status codes and flag-set selection aligned with the main API.

Important failure modes

TriggerConsequenceGuard
Authentication is enabled and the request has no valid API key.The request is rejected before evaluation.Configure the client with X-API-Key or Authorization: Bearer <key>.
An admin request has no valid admin key.The retriever refresh or flag validation request is rejected, even if evaluation authentication is disabled.Use a key from the configured admin-key set.
Flag-set mode receives a key that is not mapped to a running flag set.The evaluation or collector handler cannot select a client and returns a bad-request error.Keep API keys mapped to an active flag set.
GO Feature Flag request has neither user nor evaluationContext.The request is invalid.Send one supported context form.
OFREP request has a missing or null context.The endpoint returns an invalid-context error with HTTP 400.Send a context object. It may be empty when the flag does not need a targeting key.
An OFREP flag needs bucketing but the context has no targetingKey.Single evaluation returns a bad evaluation error.Include a stable targeting key for percentage or other bucketing rules.
A validation request omits or uses an unsupported Content-Type.The endpoint returns HTTP 415 without validating the body.Send JSON, YAML, or TOML with the matching supported media type.
A validation body is above the limit for its format.The endpoint returns HTTP 413 and does not validate the file.Keep the body within the configured format limit.
A validation file parses but contains invalid flag definitions.The endpoint returns HTTP 422 with the invalid flags and messages.Fix the reported definitions before loading the file.
A collector batch contains malformed event records.Those records are skipped while other records continue. The returned count is the request record count.Validate provider event shape before sending the batch.
A collector request is cancelled during a large batch.Processing stops after a partial batch and returns a cancellation error.Use request timeouts that allow the intended batch to finish.
An SSE client uses an API key from another flag set.The client is authorized only if the key is valid, but it receives the stream for the key’s mapped flag set.Treat the API key as the source of stream identity and do not hard-code a different stream.
An SSE client omits apiKey in flag-set mode.The connection is rejected with HTTP 400 before it subscribes to a stream.Include the API key in the SSE query string.
A WebSocket client uses an API key that cannot resolve a flag set.The connection is rejected with HTTP 400 before the WebSocket upgrade.Use a key mapped to the intended flag set.
A WebSocket write or read fails.The connection is removed and no longer receives change notices.Reconnect the client and reload state as needed.
The metrics service is not configured.The /metrics endpoint is not registered.Provide the metrics service when monitoring data is required.
Profiling is requested while debug mode and profiling are both disabled.The profiling endpoint is not available.Enable debug mode or profiling only in environments that need it.
A dedicated monitoring port is configured but a client calls monitoring paths on the API listener.The monitoring endpoint is not available at that address.Send health, information, metrics, and profiling requests to the effective monitoring listener.
The proxy stops before HTTP handling ends or flag sets close too early.In-flight work can fail and buffered evaluation data may not flush.Keep stream close, HTTP stop, and final flag-set close in the defined order.
A runtime flag-set update is invalid or changes an unsupported property.The last working routing and flag-set state remains active.Validate the full update and apply only supported changes.

Key files

FileWhy to read it
cmd/…/server.goShows how evaluation handlers, admin handlers, services, authentication, monitoring, and stream services are composed.
cmd/…/server_lifecycle.goShows how HTTP, Unix socket, Lambda, monitoring, tracing, and shutdown lifecycles are selected.
cmd/…/routes_goff.goDefines the GO Feature Flag evaluation, collection, configuration, and flag-change routes.
cmd/…/routes_ofrep.goDefines the OFREP single and bulk evaluation routes and their bulk-response cache behavior.
cmd/…/routes_admin.goDefines the admin-only refresh and flag-file validation routes.
cmd/…/routes_monitoring.goDefines health, service information, metrics, and conditional profiling endpoints on the correct listener.
cmd/…/body_dump_handler.goDefines the safe debug logging behavior for request bodies.
cmd/…/routes_cors_test.goDemonstrates the browser CORS contract for API and monitoring requests.
cmd/…/routes_monitoring_test.goDemonstrates profiling availability and version-header behavior on both listeners.
cmd/…/routes_stream_test.goDemonstrates the deprecation headers for the old WebSocket flag-change path.
cmd/…/lambda_handler_test.goDemonstrates the supported Lambda event adapters and gateway base-path behavior.
cmd/…/flag_eval.goShows the single-flag GO Feature Flag request and fallback response flow.
cmd/…/all_flags.goShows the GO Feature Flag bulk evaluation flow and snapshot response.
cmd/…/evaluate.goShows OFREP context validation, single evaluation, bulk evaluation, and error status behavior.
cmd/…/validate_flags.goShows flag-file validation inputs, result shape, size limits, and status behavior.
cmd/…/config_endpoints.goDefines the per-format validation body limits and their defaults.
cmd/…/collect_eval_data.goShows cached event ingestion and handoff to flag-set exporters.
cmd/…/sse_flag_change.goShows API-key resolution and flag-set scoping for SSE clients.
cmd/…/ws_flag_change.goShows API-key resolution, WebSocket registration, keep-alive behavior, and connection cleanup.
cmd/…/sse_flag_change_test.goDemonstrates SSE event delivery, flag-set isolation, and invalid API-key behavior.
cmd/…/ws_flag_change_test.goDemonstrates WebSocket delivery, flag-set isolation, legacy-path support, and connection errors.
cmd/…/handlers_test.goDemonstrates manifest responses, capability headers, and flag-set selection.
cmd/…/flagset_manager.goDefines API-key routing to the default or named flag set.
cmd/…/flagset_manager_test.goDemonstrates runtime API-key and flag-set changes, validation, and preservation of the last valid state.
cmd/…/main.goShows service assembly and the shutdown order for streams, HTTP handling, and flag-set exporters.
cmd/…/main_test.goVerifies that shutdown stops request handling before closing flag sets.
cmd/…/user_request.goDefines the GO Feature Flag request context and fallback value.
cmd/…/ofrep_requests.goDefines the OFREP evaluation context request.
cmd/…/ofrep_success_response.goDefines the OFREP single-evaluation success shape.
cmd/…/ofrep_error_response.goDefines common and flag-specific OFREP error shapes.
cmd/…/notifier_sse.goShows how flag changes are scoped to an SSE flag-set stream.
cmd/…/sse.goShows the SSE subscription and publication contract.
cmd/…/websocket.goShows WebSocket registration and broadcast behavior.