Skip to main content

API and Programmatic Usage

For automated workflows, CI/CD pipelines, and custom applications, you can deploy security prompts programmatically through LLM provider APIs. This gives you full control over prompt versioning, model selection, and runtime behavior.

To ground prompts in your own coding standards, framework references, or past findings, see Retrieval-Augmented Generation (RAG), which retrieves relevant context at query time and injects it into the prompt.

OpenAI API​

Pass the security prompt as the system message in the Chat Completions API:

from openai import OpenAI

client = OpenAI()

# Load the security prompt from a file
with open("prompts/js/express/5.2/prompt.md") as f:
security_prompt = f.read()

response = client.chat.completions.create(
model="gpt-6-astra",
messages=[
{"role": "system", "content": security_prompt},
{"role": "user", "content": "Write an Express.js login endpoint"}
]
)

print(response.choices[0].message.content)

With the Responses API​

response = client.responses.create(
model="gpt-6-astra",
instructions=security_prompt,
input="Write an Express.js login endpoint"
)

print(response.output_text)

Anthropic API​

Pass the security prompt as the system parameter:

import anthropic

client = anthropic.Anthropic()

with open("prompts/python/django/5.2/prompt.md") as f:
security_prompt = f.read()

message = client.messages.create(
model="claude-opus-5-5",
max_tokens=4096,
system=security_prompt,
messages=[
{"role": "user", "content": "Write a Django authentication view"}
]
)

print(message.content[0].text)

Google Gemini API​

Pass the security prompt as system_instruction:

from google import genai

client = genai.Client()

with open("prompts/jvm/spring-boot/3.5/prompt.md") as f:
security_prompt = f.read()

response = client.models.generate_content(
model="gemini-4-argon",
config=genai.types.GenerateContentConfig(
system_instruction=security_prompt
),
contents="Write a Spring Boot REST controller with authentication"
)

print(response.text)

OpenRouter​

OpenRouter provides a unified API that routes to multiple model providers. It uses the OpenAI-compatible format:

from openai import OpenAI

client = OpenAI(
base_url="https://openrouter.ai/api/v1",
api_key="your-openrouter-key"
)

with open("prompts/go/go/1.27/prompt.md") as f:
security_prompt = f.read()

response = client.chat.completions.create(
model="google/gemini-4-argon",
messages=[
{"role": "system", "content": security_prompt},
{"role": "user", "content": "Write an HTTP handler with input validation in Go"}
]
)

print(response.choices[0].message.content)

Tips​

  • OpenRouter lets you switch models without changing your code — just change the model parameter
  • The same system prompt format works across all OpenRouter-supported models

Loading Prompts from Files​

All the examples above load the prompt from a file at runtime. This is the recommended pattern because it:

  • Keeps prompt content out of your application code
  • Makes updates simple — when a new prompt release arrives, replace the file and restart the service
  • Enables version control of prompt files alongside code
  • Supports environment-specific prompts (dev, staging, production)

Copy the prompts you use from your prompt repo into your project. See Prompt Delivery for the folder layout.

Dynamic Prompt Selection​

If your application supports multiple frameworks, select the prompt at runtime from prompts/index.json, which lists every prompt in the release by id:

import json
import os

with open("prompts/index.json") as f:
PROMPTS = json.load(f)["prompts"]

def get_security_prompt(prompt_id: str) -> str:
entry = PROMPTS.get(prompt_id)
if not entry:
raise ValueError(f"No security prompt with id: {prompt_id}")
with open(os.path.join("prompts", entry["path"])) as f:
return f.read()

# Usage
security_prompt = get_security_prompt("python/django/5.2")

This is useful for platforms that serve multiple teams or projects using different technology stacks.