# Custom instructions and context

## Add a system prompt and AGENTS.md

Send both as top-level UTF-8 strings. Use `system_prompt` for response behaviour and `agents_md` for project rules.

~~~json
{
  "model": "deepseek-v4.1-flash-1017",
  "system_prompt": "Use British English and answer in two sentences.",
  "agents_md": "# Project rules\nUse table-driven tests and descriptive test names.",
  "messages": [{"role": "user", "content": "Suggest a test for our string parser."}],
  "max_tokens": 256
}
~~~

| Field | Maximum UTF-8 size |
|---|---:|
| `system_prompt` | 150 KB |
| `agents_md` | 200 KB |

Use the file’s text as the value of `agents_md`. The system prompt, project rules, history and reply share the model’s context window. Keep the rules that matter to the current task and use a model with enough room for the complete request.

## Send a local file

This Bash example needs `jq`. It preserves the file’s line breaks when producing JSON.

~~~bash
jq -n --rawfile agents AGENTS.md '{
  model: "deepseek-v4.1-flash-1017",
  messages: [{role: "user", content: "Suggest a test for our string parser."}],
  system_prompt: "Answer concisely.",
  agents_md: $agents,
  max_tokens: 256
}' | curl --fail-with-body -sS https://site6.eokgg.win/v1/chat/completions \
  -H "Authorization: Bearer $SITE6_API_KEY" \
  -H 'Content-Type: application/json' \
  --data-binary @-
~~~

[Read the file in Python, TypeScript, PowerShell and other languages](/examples/).

## Keep instructions on follow-ups

Include the fields on each new request, including a Responses continuation with `previous_response_id`. Server tools run within the original request and their follow-up generations carry its instructions. Clients that call a function and submit its result in a new request should resend the settings.

Attach a document as [a file](/files/) when you want the model to read it as source material. The `agents_md` field is for project instructions that should guide the answer.

## Budget for long requests

Check the selected model's `context_length` via [GET /v1/models](/models/#discover-your-models). Context includes your instructions, user and assistant turns, tool definitions, tool results, attachment content and the reply. A `previous_response_id` saves you from resending the stored inputs over HTTP. Those inputs still count towards the conversation's context.

The request size limit is separate from the model's token budget. This Node.js check measures the exact UTF-8 bytes before sending a JSON request.

~~~javascript
const json = JSON.stringify(payload);
const requestBytes = Buffer.byteLength(json, "utf8");
const systemBytes = Buffer.byteLength(payload.system_prompt ?? "", "utf8");
const agentsBytes = Buffer.byteLength(payload.agents_md ?? "", "utf8");
console.log({ requestBytes, systemBytes, agentsBytes });
~~~

Check the values against the [request limits](/usage/#request-limits). To estimate context tokens, use the selected model's tokenizer when you have access to it. UTF-8 bytes and token counts measure different things.

## Keep the relevant history

- Include the project rules that apply to the current task. Link other files from the rules when your application can load those files on demand.
- Leave room for the answer and tool results. If a lookup returns a long document, carry forward the relevant excerpt and its source.
- For a new thread with a summary, keep the user requirements and outstanding actions explicit. Preserve any outstanding tool call IDs until you submit their results.

If the API returns `context_length_exceeded`, select a model with a larger advertised context or reduce the request yourself. The [Codex adapter](/examples/#codex) documents compaction for Stupid AI.
