DocumentationApplications & proxy

OpenAI Chat Completions

Send a server-side Chat Completions request with explicit Kastra and upstream credentials.

Updated 2026-09-22 Read as Markdown
On this page

Prepare a test request

Set KASTRA_API_KEY and OPENAI_API_KEY in your server environment. Choose a model your provider account can access. Create a request.json file:

{
  "model": "REPLACE_WITH_YOUR_OPENAI_MODEL",
  "messages": [{"role": "user", "content": "Reply with a short greeting."}],
  "stream": false
}

Replace the model placeholder before sending. This example produces no tool side effect.

curl -i https://api.kastra.ai/v1/chat/completions \
  -H "Authorization: Bearer $KASTRA_API_KEY" \
  -H "X-Upstream-API-Key: $OPENAI_API_KEY" \
  -H 'Content-Type: application/json' \
  -H 'X-Jurisdiction: US' \
  --data-binary @request.json

Choose the jurisdiction your policy expects; it is policy context, not a data-residency selector.

Read the response

Inspect X-Policy-Decision and, when present, X-Policy-Pre-Decision and X-Policy-Post-Decision. Decode structured errors even on non-2xx responses. A provider success status alone is not sufficient permission to execute a generated tool.

Add tools and approvals

Start with a harmless test tool and configure a policy that matches the actual output tool name and arguments. Handle blocked or held output before dispatching the tool. Output and streaming guide, approval contract.

Endpoint boundary

This guide covers Chat Completions. It does not document /v1/responses, assistants, image generation, or arbitrary OpenAI endpoints as Kastra proxy routes. Use the evaluation API for a custom cooperative authorization integration.