---
title: "Validate Llm Connection"
method: POST
path: "/agents/validate-llm"
tags: ["Agents"]
---

# Validate Llm Connection

`POST /agents/validate-llm`

Validate an LLM provider API key and model availability.

Two callable shapes:

- **Inline** - raw ``apiKey`` + optional ``baseUrl`` supplied directly.
  Used when the user is pasting a fresh key in the form.
- **Saved connection** - ``savedConnectionId`` references a stored
  ``llmConnection``; BE loads the decrypted ``apiKey`` + ``baseUrl`` +
  ``provider`` server-side so the browser never holds the plaintext.

Calls the provider's free list-models endpoint to check key validity
and model existence. The "apiKey required unless ollama or saved" rule
is enforced by the request model's ``@model_validator``.
Per-tenant rate limit: 30 req/min/bucket -> 429 with ``Retry-After``.

## Request body

- ValidateLlmRequest — Request body for POST /agents/validate-llm. Two callable shapes: 1. **Inline** - ``apiKey`` (+ optional ``baseUrl``) supplied directly. Used when the user is pasting a fresh key in the form. 2. **Saved connection** - ``savedConnectionId`` references a row in ``agent_connections.llmConnections``. The BE loads the decrypted ``apiKey`` / ``baseUrl`` server-side so the browser never has to hold (or re-send) a stored plaintext to test it. Mirrors the MCP ``savedConnectionId`` discovery path.
  - `provider` 'anthropic' | 'openai' | 'openai-responses' | 'ollama' | 'azure' | 'azure-openai' | 'bedrock' | 'qwen' | 'openai-compatible', required — Unified LLM provider enum. A single ``AgentLlmConnection`` row carries one provider and a set of capabilities (chat / embedding). ``PROVIDER_CAPABILITIES`` below pins which capabilities each provider can serve — picked by the FE Connections drawer and re-validated server-side on every write.
  - `model` string
  - `apiKey` string — Raw key - never stored
  - `baseUrl` string, nullable
  - `savedConnectionId` string, nullable — If set, BE resolves provider/apiKey/baseUrl from the tenant's saved llmConnection by id and ignores the inline ``apiKey`` / ``baseUrl``.

## Response `200`

Successful Response

- object

## Other responses

- `422` — Validation Error

---

[API](https://skmtc.net/streamkap/apis/streamkap-rest-api.md) · [All operations](https://skmtc.net/streamkap/apis/streamkap-rest-api/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/streamkap/streamkap-rest-api/versions/8aea6143d003/schema)
