Skip to main content

Chat API

The Chat API combines Ground’s search with GPT-4 to provide AI-powered answers backed by real documentation. Every response includes citations to the original sources.

Endpoint

POST /chat

Request

query
string
required
The question to ask the Ground Agent
top_k
integer
default:"5"
Number of sources to use as context (1-10)
max_context_tokens
integer
default:"4000"
Maximum tokens for context window
include_global
boolean
default:"true"
Include pre-indexed global packages in search

Response

answer
string
AI-generated answer based on Ground’s indexed documentation
citations
array
List of sources used to generate the answer
search_time_ms
number
Time taken to search Ground’s index
completion_time_ms
number
Time taken for AI to generate answer
total_time_ms
number
Total response time
model_used
string
AI model used (e.g., “gpt-4o”)

Example

curl -X POST https://api.trygroundai.com/chat \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "How do I use React hooks for state management?",
    "top_k": 5
  }'

Response Example

{
  "answer": "React hooks like `useState` and `useReducer` are used for state management...",
  "citations": [
    {
      "source_name": "NPM: react",
      "content": "useState is a Hook that lets you add React state to function components...",
      "score": 0.95,
      "path": "react/index.d.ts"
    },
    {
      "source_name": "NPM: jotai",
      "content": "Primitive and flexible state management for React...",
      "score": 0.89,
      "path": "jotai/package.json"
    }
  ],
  "search_time_ms": 84.5,
  "completion_time_ms": 3200.0,
  "total_time_ms": 3284.5,
  "model_used": "gpt-4o"
}

Key Features

Citation-Backed

Every answer includes references to the actual documentation

175+ Packages

Pre-indexed npm and PyPI packages for instant results

Fast Search

84ms cached search with embedding cache

GPT-4 Powered

Answers generated by GPT-4o with Ground context