Relay a chat completion
POST/openai/v1/chat/completions
Relays an OpenAI chat completion request to the chat completions API of the LLM named in the x-llm-id header. Foundation4 forwards the body with the registered model name in the model field, and sends the API key of the registration, when the registration has one, as a bearer token. The model field of the body applies only when the registration has no model name. Foundation4 returns the model server's status and body, including error responses, and performs no retrieval, prompt templating or tracing.
Permissions. Execute on the LLM.
LLMs describes the endpoint.
Request
Responses
- 200
- 400
- 401
- 403
- 404
- 500
- 501
- 502
- default
The model server's response, relayed unchanged. A non-streamed request receives the model server's body and content type, typically a chat completion object in JSON; a request with "stream": true receives the model server's server-sent events as text/event-stream.
The X-Llm-Id header is missing (Header of type `x-llm-id` was missing) or is not a valid identifier (Invalid LLM ID: <reason>), the body is not valid JSON or is not a JSON object (Request body must be a JSON object), the registration has no model name and the body has no model field (The LLM has no model; set "model" in the request), the request carries one or two of the headers X-Agent-Id, X-Pipeline-Id and X-Pipeline-Classification (Missing required headers: ...), or the endpoint of the LLM names a private, loopback or link-local address while the API server configuration sets app.allow_private_endpoints to false (Invalid parameter).
The authentication headers are missing or invalid, or the API key is inactive or expired. Errors lists the messages.
The license is not valid (Invalid license: <reason>).
No LLM with this identifier exists, or the key lacks execute permission on the LLM (LLM not found, with the identifier in details.id).
Foundation4 could not build the response from the model server's reply (Internal error).
The request carries all three headers X-Agent-Id, X-Pipeline-Id and X-Pipeline-Classification (F4ai enriched completions not implemented yet).
Foundation4 could not reach the model server (Upstream LLM request failed) or could not read the model server's response (Failed reading upstream LLM response). The API server log records the reason.
An error response of the model server, relayed with the model server's status, body and content type, or with application/json when the model server sends no content type.