> ## Documentation Index
> Fetch the complete documentation index at: https://docs.case.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Web Research

> AI-powered research with citations

**The problem:** You need to research a legal issue across multiple jurisdictions. Manual research takes days.

**The solution:** Use AI-powered web search to get answers with citations, or run deep research for comprehensive analysis.

<Warning>
  **Web data only.** This searches publicly available web content. For comprehensive legal research (case law, statutes, regulations), use specialized platforms like Lexis, Westlaw, or OpenLaws.
</Warning>

## Quick answer with citations

Let your users get AI-generated answers to questions:

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/search/v1/answer \
    -H "Authorization: Bearer $CASEDEV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "query": "What is the statute of limitations for medical malpractice in California?",
      "includeDomains": ["law.cornell.edu", "findlaw.com", "justia.com"]
    }'
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev search:v1 answer \
    --query "What is the statute of limitations?"
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import Casedev from 'casedev';

  const client = new Casedev({ apiKey: process.env.CASEDEV_API_KEY });

  // Answer your user's question
  const result = await client.search.v1.answer({
    query: userQuery, // e.g., "What is the statute of limitations for medical malpractice in California?"
    includeDomains: ['law.cornell.edu', 'findlaw.com', 'justia.com']
  });

  // Return answer with citations to your user
  console.log(result.answer);
  // "In California, the statute of limitations for medical malpractice
  //  is 3 years from the date of injury or 1 year from discovery [1]..."

  console.log('\nSources:');
  for (const citation of result.citations) {
    console.log(`[${citation.id}] ${citation.title}`);
    console.log(`    ${citation.url}`);
  }
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import casedev
  import os

  client = casedev.Casedev(api_key=os.environ['CASEDEV_API_KEY'])

  # Answer your user's question
  result = client.search.v1.answer(
      query=user_query,  # e.g., "What is the statute of limitations..."
      include_domains=['law.cornell.edu', 'findlaw.com', 'justia.com']
  )

  # Return answer with citations to your user
  print(result.answer)

  print('\nSources:')
  for citation in result.citations:
      print(f'[{citation.id}] {citation.title}')
      print(f'    {citation.url}')
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result, _ := client.Search.V1.Answer(ctx, casedev.SearchV1AnswerParams{
  	Query: casedev.F("What is the statute of limitations?"),
  })
  fmt.Println(result.Answer)
  for _, c := range result.Citations {
  	fmt.Printf("[%s] %s: %s\n", c.ID, c.Title, c.URL)
  }
  ```
</CodeGroup>

## Deep research

For complex topics, offer your users comprehensive multi-step research:

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  # Start research
  RESEARCH=$(curl -s -X POST https://api.case.dev/search/v1/research \
    -H "Authorization: Bearer $CASEDEV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "instructions": "Research non-compete agreement enforceability across US states",
      "model": "pro"
    }')

  RESEARCH_ID=$(echo $RESEARCH | jq -r '.researchId')

  # Get results
  curl "https://api.case.dev/search/v1/research/$RESEARCH_ID" \
    -H "Authorization: Bearer $CASEDEV_API_KEY"
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev search:v1 retrieve-research --id $RESEARCH_ID
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  // Start deep research for your user
  const research = await client.search.v1.research({
    instructions: userResearchTopic, // e.g., "Research non-compete agreement enforceability across US states"
    model: 'pro'  // Most thorough
  });

  console.log(`Research started: ${research.researchId}`);

  // Wait for completion
  let result = await client.search.v1.retrieveResearch(research.researchId);

  while (result.status !== 'completed') {
    console.log(`Status: ${result.status}...`);
    await new Promise(r => setTimeout(r, 10000));
    result = await client.search.v1.retrieveResearch(research.researchId);
  }

  // Deliver the report to your user
  console.log(result.report);
  console.log(`\nSources analyzed: ${result.metadata.sourcesAnalyzed}`);
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  import time

  # Start deep research for your user
  research = client.search.v1.research(
      instructions=user_research_topic,  # e.g., "Research non-compete agreement enforceability..."
      model='pro'  # Most thorough
  )

  print(f'Research started: {research.research_id}')

  # Wait for completion
  result = client.search.v1.retrieve_research(research.research_id)

  while result.status != 'completed':
      print(f'Status: {result.status}...')
      time.sleep(10)
      result = client.search.v1.retrieve_research(research.research_id)

  # Deliver the report to your user
  print(result.report)
  print(f'\nSources analyzed: {result.metadata.sources_analyzed}')
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  result, _ := client.Search.V1.GetResearch(ctx, researchID, casedev.SearchV1GetResearchParams{})
  fmt.Println(result.Status)
  fmt.Println(result.Report)
  ```
</CodeGroup>

## Web search

For simple searches, expose the search endpoint directly:

<CodeGroup>
  ```bash title="cURL" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  curl -X POST https://api.case.dev/search/v1/search \
    -H "Authorization: Bearer $CASEDEV_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "query": "SEC cryptocurrency enforcement actions 2024",
      "numResults": 20,
      "startPublishedDate": "2024-01-01",
      "excludeDomains": ["reddit.com", "twitter.com"],
      "includeText": true
    }'
  ```

  ```bash title="CLI" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  casedev search:v1 search \
    --query "search query" \
    --num-results 20 --include-text
  ```

  ```typescript title="Typescript" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  // Search on behalf of your user
  const results = await client.search.v1.search({
    query: userSearchQuery,
    numResults: 20,
    startPublishedDate: '2024-01-01',
    excludeDomains: ['reddit.com', 'twitter.com'],
    includeText: true
  });

  // Return results to your user
  for (const result of results.results) {
    console.log(`${result.title}`);
    console.log(`${result.url}`);
    console.log(`Published: ${result.publishedDate}\n`);
  }
  ```

  ```python title="Python" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  # Search on behalf of your user
  results = client.search.v1.search(
      query=user_search_query,
      num_results=20,
      start_published_date='2024-01-01',
      exclude_domains=['reddit.com', 'twitter.com'],
      include_text=True
  )

  # Return results to your user
  for result in results.results:
      print(result.title)
      print(result.url)
      print(f'Published: {result.published_date}\n')
  ```

  ```go title="Go" theme={"theme":{"light":"github-light","dark":"one-dark-pro"}}
  results, _ := client.Search.V1.Search(ctx, casedev.SearchV1SearchParams{
  	Query:      casedev.F("search query"),
  	NumResults: casedev.F(int64(20)),
  	IncludeText: casedev.F(true),
  })
  for _, r := range results.Results {
  	fmt.Println(r.Title, r.URL)
  }
  ```
</CodeGroup>

## Research models

Choose based on your users' needs:

| Model    | Time     | Depth | Use case            |
| -------- | -------- | ----- | ------------------- |
| `fast`   | \~30 sec | Basic | Quick fact-checking |
| `normal` | \~2 min  | Good  | Standard research   |
| `pro`    | \~5 min  | Best  | Complex topics      |

<Info>
  **Tip:** Use `includeDomains` to restrict results to authoritative sources like government sites and legal databases.
</Info>
