Skip to main content
🔑
Get your Incredible API key
Generate your API key to start using this endpoint

Overview

The Answer API provides a streamlined way to get direct, concise answers to questions without the complexity of managing conversation history or tool calling. It’s optimized for single-turn Q&A use cases where you need a quick response. This endpoint is particularly useful when you need to:
  • Extract specific information from your knowledge base
  • Generate quick responses to user queries
  • Transform unstructured text into structured JSON data
  • Provide answers based on document context
Unlike the Conversation or Agent endpoints, Answer is designed for stateless interactions - each request is independent, making it perfect for FAQ systems, information retrieval, and data extraction tasks.

Using Answer

The Answer endpoint is designed to generate concise answers to questions, extract information from your data, or convert unstructured text into structured formats. It’s ideal for Q&A tasks, transforming text into JSON, or providing instant, context-based responses.
from incredible_python import Incredible

client = Incredible(api_key="YOUR_API_KEY")

# Simple answer
response = client.answer(
    query="What is the meaning of life?"
)

print(response.answer)
What is query? The question or prompt you want answered. This can be a simple question, a complex query, or instructions for data transformation. The API will analyze your query and generate an appropriate response. Best practices:
  • Be specific and clear in your questions
  • Include relevant context within the query if not using files
  • For complex queries, consider breaking them into smaller questions

Working with Files

You can enhance the Answer API’s responses by providing document context. This is especially useful for answering questions about specific documents, analyzing reports, or extracting information from files. You can provide document context by uploading files first, then referencing them in your answer request:
from incredible_python import Incredible

client = Incredible(api_key="YOUR_API_KEY")

# Upload a file
with open("document.pdf", "rb") as f:
    file = client.files.upload(file=f)

# Use the file in an answer request
response = client.answer(
    query="Summarize the key points from the document",
    file_ids=[file.file_id]
)

print(response.answer)

Structured Output

The Answer API can return data in any JSON structure you define, making it incredibly powerful for data extraction and transformation tasks. By providing a response_format schema, you instruct the API to return structured data instead of plain text. This feature is ideal for:
  • Sentiment analysis - Extract sentiment and confidence scores
  • Entity extraction - Pull out names, dates, locations from text
  • Form generation - Convert descriptions into structured form data
  • Data validation - Transform unstructured input into validated structures
  • API integration - Get responses in formats that match your application’s data models
Here’s how to request structured output:
from incredible_python import Incredible

client = Incredible(api_key="YOUR_API_KEY")

schema = {
    "type": "object",
    "properties": {
        "sentiment": {"type": "string", "enum": ["positive", "negative", "neutral"]},
        "confidence": {"type": "number"}
    },
    "required": ["sentiment"]
}

response = client.answer(
    query="Analyze this review: 'Great product, highly recommend!'",
    response_format=schema
)

print(response.data)  # {"sentiment": "positive", "confidence": 0.95}

Streaming Responses

For longer answers or when you want to provide immediate feedback to users, enable streaming by setting stream: true. Instead of waiting for the complete answer, you’ll receive chunks of text as they’re generated, creating a more interactive and responsive experience. When to use streaming:
  • Long-form answers or explanations
  • Interactive user interfaces where immediate feedback is valuable
  • Reducing perceived latency for users
  • Building chat-like experiences
How it works: The API sends answer fragments in real-time as they’re generated. Your application can display these fragments immediately, creating a typewriter effect that keeps users engaged while the full response is being computed.
from incredible_python import Incredible

client = Incredible(api_key="YOUR_API_KEY")

# Stream an answer
stream = client.answer(
    query="Write a detailed explanation of quantum computing",
    stream=True
)

# Process streaming chunks
for chunk in stream:
    if hasattr(chunk, 'content') and chunk.content:
        print(chunk.content, end='', flush=True)
    if hasattr(chunk, 'done') and chunk.done:
        print("\n[Stream complete]")
Stream Event Types:
  • content - Text chunks as they’re generated
  • thinking - Internal reasoning process (if available)
  • done - Signals completion of the stream
  • error - Any errors that occurred during generation