Answer API

Version 2.197 (Release Notes ↗)

Description

The Answer API endpoint returns concise responses to natural-language questions over a simple stateless interface. It is useful when you need single-turn Q&A inside search tools, support flows, internal assistants, onboarding helpers, documentation lookup, or lightweight product features without maintaining conversation state.

This endpoint is a streamlined way to access PixLab's language models for direct answers while keeping integration overhead low. If you need multi-turn chat, tool use, or richer conversational state, move up to the CHAT endpoint instead.

HTTP Methods

GET, POST

HTTP Parameters

Required

Fields Type Description
query string Question or prompt to be answered by the underlying language model.
key String Your PixLab API Key ↗. You can also send the key in the WWW-Authenticate HTTP header and omit this parameter.

Optional

Fields Type Description
format string Specify the output format for the generated answer. Supported values are text (default), json, and markdown.
openai-reply boolean If set to true, return a response object compatible with OpenAI-style clients. Otherwise, the endpoint returns the PixLab simple format shown below.

Optional LLM Parameters

For most applications, the default LLM parameter values are a good starting point. Only change these values if you have a solid grasp of how each parameter works.

Fields Type Description
temperature float The sampling temperature, ranging from 0 to 2, influences the randomness of the output. Higher values, such as 0.8, increase randomness, whereas lower values, such as 0.2, promote focused and deterministic outputs. It is generally recommended to adjust either this parameter or top_p, but not both simultaneously.
max_tokens integer An integer between 1 and 180,000, representing the maximum number of tokens to be generated in a chat completion. The combined length of input and generated tokens is constrained by the model's context length.
frequency_penalty float A number between -2.0 and 2.0. Positive values penalize new tokens according to their frequency in the preceding text, thereby reducing the model's tendency to repeat phrases verbatim.
presence_penalty float A number between -2.0 and 2.0. Positive values penalize new tokens based on their presence in the preceding text, thus encouraging the model to explore novel topics.
top_p float An alternative to temperature-based sampling is nucleus sampling, which considers tokens based on the top_p probability mass. For example, a top_p value of 0.1 means only the tokens within the top 10% of the probability mass are considered. It's generally recommended to adjust either top_p or temperature, but not both.
logprobs boolean Indicates whether to return log probabilities for the output tokens. If set to true, the log probabilities of each output token will be included in the message content.
top_logprobs integer An integer between 0 and 20, indicating the number of most probable tokens to return at each token position, along with their associated log probabilities. If this parameter is used, logprobs must be set to true

POST Request Body

Use a POST request when you prefer sending the prompt and optional parameters in a JSON body instead of query parameters.

Allowed Content-Types:

  • application/json

For application/json requests, send your question in the query field along with your API key and any optional LLM parameters. This endpoint is text-only and does not require file uploads.

HTTP Response

application/json

By default, this endpoint returns the PixLab simple response format, which includes the generated answer plus token usage and model metadata. If you need an OpenAI-compatible response format, set the openai-reply boolean HTTP parameter to true.

PixLab Simple Answer Response Format


{
  "status": 200,
  "id": "6783E34342",
  "output": "Fully generated output by the underlying LLM",
  "role": "Role of the output generator",
  "format": "Desired output format",
  "object": "chat",
  "created": 1694623155,
  "model": "pix-llm",
  "total_input_tokens": 25,
  "total_output_tokens": 57
}
Fields Type Description
status Integer HTTP 200 indicates success. Any other code indicates failure.
id String Unique identifier for the generated response.
output String Generated answer returned by the underlying language model.
role String Role associated with the generated response, typically assistant.
format String Output format selected through the format parameter, such as text, json, or markdown.
object String Underlying PixLab LLM endpoint used to generate the response.
created Timestamp Unix timestamp for when the response was generated.
model String Identifier of the model used to generate the answer.
total_input_tokens Integer Total number of input tokens processed for the request.
total_output_tokens Integer Total number of output tokens generated for the response.
error String Error details returned when status != 200.

OpenAI Compatible Response Format

An OpenAI-compatible ↗ response format will be returned when the openai-reply boolean HTTP parameter is set to true:


{
  "status": 200,
  "id": "6783E34342",
  "object": "chat",
  "created": 1694623155,
  "model": "pix-llm",
  "choices": [
    {
      "index": 0,
      "message": {
          "role": "assistant",
          "content": "Hello! How can I help you today?"
      },
      "finish_reason": "stop"
    }
  ],
  "usage": {
      "prompt_tokens": 15,
      "completion_tokens": 16,
      "total_tokens": 31
    }
}
              

Code Samples


# For a comprehensive list of production-ready code samples, please consult the PixLab GitHub Repository: https://github.com/symisc/pixlab.

← Return to API Endpoint Listing