Files
coder/docs/reference/api/aigateway.md
T
Ethan 3795d72713 fix: search AI Gateway models and clients by substring (#32159)
Closes AIGOV-801

Typing `hai` into the model filter on the AI Gateway sessions page shows
the haiku models for a moment, then "No models found". Whilst the
debounced request is pending, the menu filters the options it already
has by a case-insensitive substring, but `GET /api/v2/ai-gateway/models`
only matched a case-sensitive prefix, and Bedrock identifiers start with
`anthropic.`. The client filter matched the same way, so it had the same
problem.

To fix, both endpoints now match a case-insensitive substring.

This needed one change to the model menu. When the page loads with a
model already in the filter, the menu used to look that model up on the
server, by searching for its name and taking the first result. That's
the same pattern as the user filter, where the lookup fetches the
avatar, but a model option needs nothing from the server, so all it did
was check that the model exists. With a substring search, the first
result for `claude-3-5-sonnet-20241022` can be
`anthropic.claude-3-5-sonnet-20241022-v2:0`, so the check would fail for
a model that does exist. The menu now skips the lookup and just shows
the model from the filter as selected. The only visible difference is
that a model name in the URL that doesn't exist now shows as selected,
instead of "All models". The client menu has the same lookup, which
still works, as no client name contains another, so I've left it alone.

The prefix match was added in #22230 (models) and #22694 (clients) so
the queries could use the B-tree indexes. That only works on a C
collation database, and only for models, as the clients query wraps the
column in `COALESCE`. On an `en_US.utf8` database it's a plain filter
either way. On a C collation database a model search with no matches
does get slower, from instant to a few seconds with 5M synthetic rows,
but I think that's worth it for a search that works.
2026-11-17 11:52:12 +11:00

13 KiB
Generated

title
title
AI Gateway

List AI Gateway clients

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai-gateway/clients \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /api/v2/ai-gateway/clients

Alias: also available at /api/v2/aibridge/clients for backward compatibility.

Example responses

200 Response

[
  "string"
]

Responses

Status Meaning Description Schema
200 OK OK array of string

Response Schema

To perform this operation, you must be authenticated. Learn more.

List AI Gateway models

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai-gateway/models \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /api/v2/ai-gateway/models

Alias: also available at /api/v2/aibridge/models for backward compatibility.

Parameters

Name In Type Required Description
q query string false Search query in the format key:value. Available keys are: model. A bare term searches by model. The match is a case-insensitive substring.
model query string false Literal model identifier substring, matched case-insensitively. Cannot be combined with q.

Example responses

200 Response

[
  "string"
]

Responses

Status Meaning Description Schema
200 OK OK array of string

Response Schema

To perform this operation, you must be authenticated. Learn more.

List AI Gateway providers

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai-gateway/providers \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /api/v2/ai-gateway/providers

Example responses

200 Response

[
  {
    "display_name": "string",
    "icon": "string",
    "name": "string",
    "type": "openai"
  }
]

Responses

Status Meaning Description Schema
200 OK OK array of codersdk.AIBridgeProvider

Response Schema

Status Code 200

Name Type Required Restrictions Description
[array item] array false
» display_name string false
» icon string false
» name string false
» type codersdk.AIProviderType false

Enumerated Values

Property Value(s)
type anthropic, azure, bedrock, copilot, google, openai, openai-compat, openrouter, vercel

To perform this operation, you must be authenticated. Learn more.

List AI Gateway sessions

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai-gateway/sessions \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /api/v2/ai-gateway/sessions

Alias: also available at /api/v2/aibridge/sessions for backward compatibility.

Parameters

Name In Type Required Description
q query string false Search query in the format key:value. Available keys are: initiator, provider, provider_name, model, client, session_id, started_after, started_before.
limit query integer false Page limit
after_session_id query string false Cursor pagination after session ID (cannot be used with offset)
offset query integer false Offset pagination (cannot be used with after_session_id)

Example responses

200 Response

{
  "count": 0,
  "sessions": [
    {
      "client": "string",
      "ended_at": "2019-08-24T14:15:22Z",
      "id": "string",
      "initiator": {
        "avatar_url": "http://example.com",
        "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
        "name": "string",
        "username": "string"
      },
      "last_active_at": "2019-08-24T14:15:22Z",
      "last_prompt": "string",
      "metadata": {
        "property1": null,
        "property2": null
      },
      "models": [
        "string"
      ],
      "network_calls": {
        "blocked": 0,
        "total": 0
      },
      "providers": [
        "string"
      ],
      "started_at": "2019-08-24T14:15:22Z",
      "threads": 0,
      "token_usage_summary": {
        "cache_read_input_tokens": 0,
        "cache_write_input_tokens": 0,
        "input_tokens": 0,
        "output_tokens": 0
      }
    }
  ]
}

Responses

Status Meaning Description Schema
200 OK OK codersdk.AIBridgeListSessionsResponse

To perform this operation, you must be authenticated. Learn more.

Get AI Gateway session threads

Code samples

# Example request using curl
curl -X GET http://coder-server:8080/api/v2/ai-gateway/sessions/{session_id} \
  -H 'Accept: application/json' \
  -H 'Coder-Session-Token: API_KEY'

GET /api/v2/ai-gateway/sessions/{session_id}

Alias: also available at /api/v2/aibridge/sessions/{session_id} for backward compatibility.

Parameters

Name In Type Required Description
session_id path string true Session ID (client_session_id or interception UUID)
after_id query string false Thread pagination cursor (forward/older)
before_id query string false Thread pagination cursor (backward/newer)
limit query integer false Number of threads per page (default 50)

Example responses

200 Response

{
  "client": "string",
  "ended_at": "2019-08-24T14:15:22Z",
  "id": "string",
  "initiator": {
    "avatar_url": "http://example.com",
    "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
    "name": "string",
    "username": "string"
  },
  "metadata": {
    "property1": null,
    "property2": null
  },
  "models": [
    "string"
  ],
  "network_call_logs": [
    {
      "allowed": true,
      "captured_at": "2019-08-24T14:15:22Z",
      "created_at": "2019-08-24T14:15:22Z",
      "detail": "string",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "matched_rule": "string",
      "method": "string",
      "proto": "string",
      "sequence_number": 0,
      "session_id": "1ffd059c-17ea-40a8-8aef-70fd0307db82"
    }
  ],
  "network_calls": {
    "blocked": 0,
    "total": 0
  },
  "network_domain_count": 0,
  "network_top_domains": [
    {
      "count": 0,
      "domain": "string"
    }
  ],
  "page_ended_at": "2019-08-24T14:15:22Z",
  "page_started_at": "2019-08-24T14:15:22Z",
  "providers": [
    "string"
  ],
  "started_at": "2019-08-24T14:15:22Z",
  "threads": [
    {
      "agent_firewall_sequence_number": 0,
      "agent_firewall_session_id": "3735294f-18b1-4e7a-a269-99c30f0b30e7",
      "agentic_actions": [
        {
          "attribution": {
            "property1": "string",
            "property2": "string"
          },
          "interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
          "model": "string",
          "priced_model": {
            "cache_read_price": 0,
            "cache_write_price": 0,
            "input_price": 0,
            "model": "string",
            "output_price": 0
          },
          "thinking": [
            {
              "text": "string"
            }
          ],
          "token_usage": {
            "cache_read_input_tokens": 0,
            "cache_write_input_tokens": 0,
            "cost_micros": 0,
            "has_unpriced_usage": true,
            "input_tokens": 0,
            "metadata": {
              "property1": null,
              "property2": null
            },
            "output_tokens": 0
          },
          "tool_calls": [
            {
              "created_at": "2019-08-24T14:15:22Z",
              "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
              "injected": true,
              "input": "string",
              "interception_id": "34d9b688-63ad-46f4-88b5-665c1e7f7824",
              "metadata": {
                "property1": null,
                "property2": null
              },
              "provider_response_id": "string",
              "server_url": "string",
              "tool": "string"
            }
          ]
        }
      ],
      "attribution": {
        "property1": "string",
        "property2": "string"
      },
      "credential_hint": "string",
      "credential_kind": "string",
      "ended_at": "2019-08-24T14:15:22Z",
      "error_message": "string",
      "error_type": "string",
      "id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
      "model": "string",
      "priced_model": {
        "cache_read_price": 0,
        "cache_write_price": 0,
        "input_price": 0,
        "model": "string",
        "output_price": 0
      },
      "prompt": "string",
      "provider": "string",
      "started_at": "2019-08-24T14:15:22Z",
      "token_usage": {
        "cache_read_input_tokens": 0,
        "cache_write_input_tokens": 0,
        "cost_micros": 0,
        "has_unpriced_usage": true,
        "input_tokens": 0,
        "metadata": {
          "property1": null,
          "property2": null
        },
        "output_tokens": 0
      }
    }
  ],
  "token_usage_summary": {
    "cache_read_input_tokens": 0,
    "cache_write_input_tokens": 0,
    "cost_micros": 0,
    "has_unpriced_usage": true,
    "input_tokens": 0,
    "metadata": {
      "property1": null,
      "property2": null
    },
    "output_tokens": 0
  }
}

Responses

Status Meaning Description Schema
200 OK OK codersdk.AIBridgeSessionThreadsResponse

To perform this operation, you must be authenticated. Learn more.