> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prismgateway.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Quickstart

> Send your first Prism chat request in a few minutes

# Quickstart

<Steps>
  <Step title="Create an API key">
    Sign in to the developer console, open **API keys**, and create a key. New
    keys begin with `sk-prism-` and are revealed only once.
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export PRISM_BASE_URL="https://api.prismgateway.io/v1"
    export PRISM_API_KEY="sk-prism-..."
    ```
  </Step>

  <Step title="Check credits and select a trial chat model">
    ```bash theme={null}
    prism_get_json() {
      local response status body action help_url
      if ! response="$(curl -sS -w '\n%{http_code}' "$@")"; then
        echo "Could not reach the Prism API." >&2
        return 1
      fi
      status="${response##*$'\n'}"
      body="${response%$'\n'*}"
      if ! echo "$body" | jq -e . >/dev/null; then
        printf 'Prism returned invalid JSON (HTTP %s).\n' "$status" >&2
        return 1
      fi
      case "$status" in
        2??) printf '%s' "$body"; return 0 ;;
      esac

      echo "$body" | jq . >&2
      if [ "$status" = "402" ]; then
        action="$(echo "$body" | jq -r '.error.action // empty')"
        help_url="$(echo "$body" | jq -r '.error.help_url // empty')"
        case "$action" in
          top_up) echo "Top up: $help_url" >&2 ;;
          contact_org_admin) echo "Contact your organization administrator." >&2 ;;
        esac
      fi
      return 1
    }

    PRISM_CREDIT_SUMMARY="$(
      prism_get_json "$PRISM_BASE_URL/credits" \
        -H "Authorization: Bearer $PRISM_API_KEY"
    )" || exit 1
    echo "$PRISM_CREDIT_SUMMARY" | jq '{balance_minor, spent_minor}'

    PRISM_TRIAL_POLICY="$(
      prism_get_json "$PRISM_BASE_URL/trial-policy"
    )" || exit 1
    PRISM_MODEL_CATALOG="$(
      prism_get_json "$PRISM_BASE_URL/models" \
        -H "Authorization: Bearer $PRISM_API_KEY"
    )" || exit 1

    export PRISM_MODEL="$(
      jq -nr \
        --argjson policy "$PRISM_TRIAL_POLICY" \
        --argjson catalog "$PRISM_MODEL_CATALOG" \
        '$policy.allowed_models as $allowed |
          first($catalog.data[].id |
            select(. as $id | $allowed | index($id))) // empty'
    )"

    test -n "$PRISM_MODEL" || {
      echo "No trial chat model is available to this key." >&2
      exit 1
    }
    ```

    Signup does not by itself guarantee welcome credit. `balance_minor` is an
    aggregate across credit kinds, so `/v1/models` is the authoritative admission
    check. On `402`, the example follows the typed `error.action`; authentication,
    policy, rate-limit, and server failures are surfaced unchanged. The command
    also intersects the public trial policy with the authenticated catalog, so
    it cannot select a hidden or policy-denied model. Paid and organization
    accounts should use a chat model approved by their administrator instead of
    relying on catalog list position.
  </Step>

  <Step title="Create a chat completion">
    ```bash theme={null}
    curl -sS "$PRISM_BASE_URL/chat/completions" \
      -H "Authorization: Bearer $PRISM_API_KEY" \
      -H "Content-Type: application/json" \
      -d "$(jq -n --arg model "$PRISM_MODEL" '{
        model: $model,
        messages: [{role: "user", content: "Hello"}]
      }')"
    ```
  </Step>
</Steps>

The response uses the OpenAI chat-completion shape. For non-streaming chat
responses, Prism may also return:

* `x-prism-trace-id`: request ID for a later usage lookup
* `x-prism-cost-credits`: charged amount in minor credits
* `x-prism-cache`: `HIT` or `MISS` when response caching applies

<Warning>
  Never expose a Prism API key in browser code, a mobile application, a public
  repository, logs, or screenshots. Call Prism from your server.
</Warning>

[อ่านภาษาไทย](/th/quickstart)
