Este contenido no está disponible en el idioma seleccionado.
Chapter 2. Interacting with the API
Secure your interaction with the OpenShift Lightspeed API by obtaining authentication tokens, configuring request headers for Model Context Protocol (MCP) servers, and troubleshooting common authentication errors.
2.1. Authenticate API requests Copiar enlaceEnlace copiado en el portapapeles!
Authenticate every request to a protected OpenShift Lightspeed endpoint by including a bearer token in the Authorization header to ensure secure access to the API.
Procedure
Set the
Authorizationheader using the following format:Authorization: Bearer <token>Submit the request. The following example demonstrates a query sent through
curl:curl -H "Authorization: Bearer ${TOKEN}" \ -H "Content-Type: application/json" \ https://<ols_host>/v1/query \ -d '{"query": "How do I create a deployment?"}'
2.2. Provide authentication for MCP servers Copiar enlaceEnlace copiado en el portapapeles!
Authenticate proxy calls to Model Context Protocol (MCP) servers by identifying required headers and including credentials in your API request body.
Procedure
Identify required headers by calling the following endpoint:
GET /v1/mcp/client-auth-headersInclude the required credentials in the
mcp_headersfield of your JSON request body:{ "query": "Show GitHub issues", "mcp_headers": { "github-mcp": {"Authorization": "Bearer <github_token>"} } }
2.3. OpenShift Lightspeed API authentication requirements Copiar enlaceEnlace copiado en el portapapeles!
The following table lists the OpenShift Lightspeed endpoints and their authentication requirements.
| Endpoint | Method | Authentication Required | Virtual Path |
|---|---|---|---|
|
| POST | Yes |
|
|
| POST | Yes |
|
|
| GET, PUT, DELETE | Yes |
|
|
| POST | Yes |
|
|
| POST | Yes |
|
|
| POST | Yes |
|
|
| POST | Yes |
|
|
| GET | No | — |
|
| GET | No | — |
|
| GET | No | — |
2.4. Access the OpenShift Lightspeed REST API directly Copiar enlaceEnlace copiado en el portapapeles!
You can integrate Red Hat OpenShift Lightspeed with external tools and scripts by using the OpenShift Lightspeed REST API. Use the versioned endpoints to programmatically interact with the service and extend its capabilities into your existing workflows.
All versioned API endpoints use the /v1 path, such as, https://<route-host>/v1/<endpoint>.
Direct API access supports up to 100 concurrent connections. Behavior beyond this limit is currently unsupported.
Prerequisites
- OpenShift Lightspeed is installed and running thorugh the OpenShift Lightspeed Operator.
-
You have
ocorkubectlCLI access to the cluster. -
You have exposed the
lightspeed-app-serverservice by using an OpenShift route. -
You have the
ols-userClusterRole.
2.4.1. Authenticate with the API Copiar enlaceEnlace copiado en el portapapeles!
To interact with the OpenShift Lightspeed API, you must use token-based authentication. The Service validates your identity through a Kubernetes TokenReview and SubjectAccessReview (SAR) against the /ols-access URL. Every request must include a valid OpenShift bearer token in the Authorization header.
Procedure
Grant the
ols-userrole by using any of the following code:To the user:
oc adm policy add-cluster-role-to-user ols-user _<username>_To the Service account:
oc adm policy add-cluster-role-to-user ols-user \ system:serviceaccount:_<namespace>_:_<service_account_name>_
Obtain a bearer token for your authentication method by any of the following ways:
For your own user:
TOKEN=$(oc whoami -t)For a Service account:
TOKEN=$(oc create token <service_account_name> -n <namespace>)
Verification
Confirm the token is valid by querying the
/authorizedendpoint:curl -k -X POST "https://${OLS_HOST}/authorized" \ -H "Authorization: Bearer ${TOKEN}"
2.4.2. OpenShift Lightspeed API endpoints reference Copiar enlaceEnlace copiado en el portapapeles!
The following versioned endpoints allow you to interact with the Service, manage conversation history, and submit user feedback.
| Endpoint | Description |
|---|---|
|
|
Sends a prompt to the LLM. Required field: |
|
|
Delivers responses as a server-sent events (SSE) stream. Supports types: |
|
| Lists conversation IDs, summaries, and message counts for the user. |
|
| Retrieves history for a specific conversation. |
|
| Deletes a specific conversation history. |
|
|
Submits sentiment ( |
2.4.3. Supported attachment formats Copiar enlaceEnlace copiado en el portapapeles!
To provide extra context such as logs or configurations, you must include an attachments array in the POST /v1/query request body.
| Attachment type | Details |
|---|---|
| Logs |
Use the |
| Configurations |
Use the |
2.4.4. OpenShift Lightspeed API error handling Copiar enlaceEnlace copiado en el portapapeles!
The OpenShift Lightspeed API returns JSON objects that contain a detail field with a response and a cause.
| Status code | Description |
|---|---|
| 401 | Unauthorized. The request is missing a token or the token is invalid. |
| 403 |
Forbidden. The user lacks the |
| 413 | Payload too large. The prompt exceeds the large language model (LLM) context window. |
| 503 | Service unavailable. The Service or LLM is still initializing. |