Using Header Classes
Sequrity provides typed Pydantic classes for each custom header
(X-Features, X-Policy, X-Config).
These classes ensure you construct valid header values with the correct structure and field types.
Download Tutorial Scripts
Sequrity Client
Imports
import os
from sequrity import SequrityClient
from sequrity.control.types import FeaturesHeader, FineGrainedConfigHeader, SecurityPolicyHeader
from sequrity.control.types.headers import FsmOverrides, PolicyCode, ResponseFormatOverrides
Building Headers
features = FeaturesHeader.dual_llm(pii_redaction=True, toxicity_filter=True)
security_policy = SecurityPolicyHeader(
codes=PolicyCode(
code=r"""
let sensitive_docs = {"internal_use", "confidential"};
tool "get_internal_document" -> @tags |= sensitive_docs;
tool "send_email" {
hard deny when (body.tags overlaps sensitive_docs)
and (not to.value in {str matching r".*@trustedcorp\.com"});
}
""",
language="sqrt",
)
)
fine_grained_config = FineGrainedConfigHeader(
fsm=FsmOverrides(
max_n_turns=10,
disable_rllm=False,
max_pllm_steps=5,
),
response_format=ResponseFormatOverrides(
include_program=True,
include_policy_check_history=True,
),
)
Sending the Request
Pass the header objects directly to chat.create:
client = SequrityClient(api_key=sequrity_key)
response = client.control.chat.create(
messages=[{"role": "user", "content": "What is the largest prime number below 100?"}],
model="openai/gpt-5-mini,openai/gpt-5-nano",
llm_api_key=openrouter_api_key,
provider="openrouter",
features=features,
security_policy=security_policy,
fine_grained_config=fine_grained_config,
)
print(response)
REST API
For raw HTTP calls, use dump_for_headers() to serialize each object to a JSON string
ready to be placed in the header value.
Imports
There are three main header classes available from sequrity.control.types corresponding to the three custom headers:
FeaturesHeaderSecurityPolicyHeader— withPolicyCodefromsequrity.control.types.headersFineGrainedConfigHeader— withFsmOverridesandResponseFormatOverridesfromsequrity.control.types.headers
import os
import requests
from sequrity.control.types import FeaturesHeader, FineGrainedConfigHeader, SecurityPolicyHeader
from sequrity.control.types.headers import FsmOverrides, PolicyCode, ResponseFormatOverrides
Building and Serializing Headers
Build the header objects as you would with the Sequrity Client, then call dump_for_headers() to get the JSON strings for the HTTP headers.
# Build each header using the Pydantic classes, then serialize for HTTP transport.
features = FeaturesHeader.dual_llm(pii_redaction=True, toxicity_filter=True)
security_policy = SecurityPolicyHeader(
codes=PolicyCode(
code=r"""
let sensitive_docs = {"internal_use", "confidential"};
tool "get_internal_document" -> @tags |= sensitive_docs;
tool "send_email" {
hard deny when (body.tags overlaps sensitive_docs)
and (not to.value in {str matching r".*@trustedcorp\.com"});
}
""",
language="sqrt",
)
)
fine_grained_config = FineGrainedConfigHeader(
fsm=FsmOverrides(
max_n_turns=10,
disable_rllm=False,
max_pllm_steps=5,
),
response_format=ResponseFormatOverrides(
include_program=True,
include_policy_check_history=True,
),
)
# dump_for_headers() serializes each object to a JSON string ready to be
# placed directly in an HTTP header value.
x_features = features.dump_for_headers()
x_policy = security_policy.dump_for_headers()
x_config = fine_grained_config.dump_for_headers()
Sending the Request
service_provider = "openrouter"
model = "openai/gpt-5-mini,openai/gpt-5-nano" # Dual-LLM: PLLM, QLLM
def chat_completion(messages):
url = f"{base_url}/control/chat/{service_provider}/v1/chat/completions"
headers = {
"Authorization": f"Bearer {sequrity_key}",
"Content-Type": "application/json",
"X-Api-Key": openrouter_api_key,
"X-Features": x_features,
"X-Policy": x_policy,
"X-Config": x_config,
}
payload = {"messages": messages, "model": model}
response = requests.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()