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

# API de Respuestas

> Respuestas de IA respaldadas por búsqueda web en vivo, scraping y crawling, no un índice obsoleto.

A través del endpoint `/v1/answers` de Olostep, puedes buscar en la web con lenguaje natural y devolver respuestas y datos impulsados por IA en el formato JSON que desees. Esto te permite basar tus productos en datos y fuentes del mundo real, enriquecer puntos de datos o hojas de cálculo.

* Haz una pregunta o proporciona a la IA un punto de datos que quieras enriquecer.
* Opcional: especifica la estructura JSON que deseas recibir.

Esto hará:

* Buscar, limpiar, validar y devolver los datos encontrados en la Web.
* Devolver las fuentes utilizadas para generar la respuesta.
* Manejar la incertidumbre con valores `NOT_FOUND` cuando los datos no puedan ser verificados.

Para detalles de la API, consulta la [Referencia de la API del Endpoint de Respuestas](/api-reference/answers/create).

Por defecto, usamos un índice web genérico y un validador LLM rentable.

Los clientes empresariales tienen acceso a índices web específicos de la industria, datos privados exclusivos (incluyendo números de teléfono y correos electrónicos) y modelos LLM personalizados más adecuados para su caso de uso. Contáctanos para obtener acceso: [info@olostep.com](mailto:info@olostep.com)

## Casos de uso

El endpoint de respuestas se puede usar para:

* Basar aplicaciones de IA en datos y hechos del mundo real.
* Enriquecer hojas de cálculo y puntos de datos para Reclutamiento, Finanzas, Consultoría y Ventas.

Aquí hay una demostración de una hoja de cálculo impulsada por IA utilizando el endpoint de Respuestas:
[https://www.olostep.com/demos/spreadsheet-enrich](https://www.olostep.com/demos/spreadsheet-enrich)

## Instalación

<CodeGroup>
  ```python Python theme={null}
  pip install olostep
  ```

  ```javascript Node theme={null}
  npm install olostep
  ```

  ```bash cURL theme={null}
  # curl está disponible por defecto en macOS, Linux y Windows
  ```

  ```javascript Node (API) theme={null}
  npm install node-fetch
  ```

  ```bash Python (API) theme={null}
  pip install requests
  ```
</CodeGroup>

## Uso

Haz una pregunta y pasa un esquema JSON para guiar la salida. También puedes no pasar el parámetro `json` y la API devolverá un objeto json con el texto de la respuesta dentro del campo `result`.

<CodeGroup>
  ```python Python theme={null}
  from olostep import Olostep

  client = Olostep(api_key="YOUR_REAL_KEY")

  answer = client.answers.create(
      task="What is the latest book by J.K. Rowling?",
      json_format={"book_title": "", "author": "", "release_date": ""},
  )

  print(answer.json_content)
  print(answer.sources)
  ```

  ```js Node theme={null}
  import Olostep from 'olostep'

  const client = new Olostep({ apiKey: 'YOUR_REAL_KEY' })

  const answer = await client.answers.create({
    task: 'What is the latest book by J.K. Rowling?',
    jsonFormat: { book_title: '', author: '', release_date: '' },
  })

  console.log(answer.json_content)
  console.log(answer.sources)
  ```

  ```bash cURL theme={null}
  curl -s -X POST "https://api.olostep.com/v1/answers" \
    -H "Authorization: Bearer $OLOSTEP_API_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "task": "What is the latest book by J.K. Rowling?",
      "json": {"book_title": "", "author": "", "release_date": ""}
    }'
  ```

  ```bash CLI theme={null}
  olostep answer "What is the latest book by J.K. Rowling?" \
    --json-format '{"book_title":"","author":"","release_date":""}'
  ```

  ```js Node (API) theme={null}
  const res = await fetch('https://api.olostep.com/v1/answers', {
    method: 'POST',
    headers: { 'Authorization': 'Bearer <YOUR_API_KEY>', 'Content-Type': 'application/json' },
    body: JSON.stringify({
      task: 'What is the latest book by J.K. Rowling?',
      json: { book_title: '', author: '', release_date: '' }
    })
  })
  console.log(await res.json())
  ```

  ```python Python (API) theme={null}
  import requests, json

  endpoint = "https://api.olostep.com/v1/answers"
  payload = {
    "task": "What is the latest book by J.K. Rowling?",
    "json": {"book_title": "", "author": "", "release_date": ""}
  }
  headers = {"Authorization": "Bearer <YOUR_API_KEY>", "Content-Type": "application/json"}

  response = requests.post(endpoint, json=payload, headers=headers)
  print(json.dumps(response.json(), indent=2))
  ```
</CodeGroup>

## Respuesta

Como otros endpoints de Olostep, recibirás un objeto `answer` en respuesta. El objeto `answer` tiene algunas propiedades como `id` y `result`.

```json theme={null}
{
  "id": "answer_9bi0sbj9xa",
  "object": "answer",
  "created": 1760327323,
  "metadata": {},
  "task": "What is the latest book by J.K. Rowling?",
  "result": {
    "json_content": "{\"book_title\":\"The Hallmarked Man\",\"author\":\"J.K. Rowling (as Robert Galbraith)\",\"release_date\":\"2 September 2025\"}",
    "json_hosted_url": "https://olostep-storage.s3.us-east-1.amazonaws.com/answer_9bi0sbj9xa.json",
    "sources": [
      "https://strikefans.com/the-books/",
      "https://www.facebook.com/groups/496943608606523/posts/1136830134617864/",
      "https://robert-galbraith.com/strike-books/",
      "https://www.novelsuspects.com/series-list/robert-galbraith-cormoran-strike-series-in-order/",
      "https://www.reddit.com/r/books/comments/1na833a/jk_rowlings_new_strike_novel_900_pages_of_romance/",
      "https://www.harrypotter.com/writing-by-jk-rowling",
      "https://stories.jkrowling.com/book-news/",
      "https://deadline.com/2024/09/jk-rowling-writing-futuristic-novel-1236093909/",
      "https://www.reddit.com/r/FantasticBeasts/comments/1cl1shn/jk_rowling_may_2024_ive_got_six_more_books_in_my/",
      "https://www.jkrowling.com/news/"
    ]
  }
}
```

La respuesta solicitada, formateada de acuerdo con el parámetro `json`, está en `response.result.json_content` y la lista de fuentes en `response.result.sources`. Puedes analizar el JSON en forma de cadena para acceder a los datos estructurados.

```json theme={null}
{
  "book_title": "The Hallmarked Man",
  "author": "J.K. Rowling",
  "release_date": "September 2, 2025"
}
```

Ejemplo de fuentes:

```json theme={null}
[
    "https://www.harrypotter.com/writing-by-jk-rowling",
    "https://stories.jkrowling.com/book-news/",
    "https://deadline.com/2024/09/jk-rowling-writing-futuristic-novel-1236093909/",
    "https://www.reddit.com/r/FantasticBeasts/comments/1cl1shn/jk_rowling_may_2024_ive_got_six_more_books_in_my/",
    "https://www.jkrowling.com/news/"
]
```

Cuando no pasas el parámetro `json`, la API devolverá un objeto json con el texto de la respuesta dentro del campo `result`.

```json theme={null}
{
  "result": "The latest book by J.K. Rowling is The Hallmarked Man."
}
```

### Parámetro `json` flexible

* Proporciona un objeto JSON con valores vacíos como esquema, o una cadena que describa los datos que deseas.
* Si el agente no está seguro, devuelve `NOT_FOUND` para ese campo.

<CodeGroup>
  ```python Python theme={null}
  from olostep import Olostep

  client = Olostep(api_key="YOUR_REAL_KEY")

  answer = client.answers.create(
      task="When will React 30 be released?",
      json_format={"release_date": ""},
  )

  print(answer.json_content)
  ```

  ```js Node theme={null}
  import Olostep from 'olostep'

  const client = new Olostep({ apiKey: 'YOUR_REAL_KEY' })

  const answer = await client.answers.create({
    task: 'When will React 30 be released?',
    jsonFormat: { release_date: '' },
  })

  console.log(answer.json_content)
  ```

  ```python Python (API) theme={null}
  import requests, json

  endpoint = "https://api.olostep.com/v1/answers"
  payload = {
    "task": "When will React 30 be released?", 
    "json": {
      "release_date": ""
    }
  }
  headers = {
    "Authorization": "Bearer <YOUR_API_KEY>",
    "Content-Type": "application/json"
  }
  response = requests.post(endpoint, json=payload, headers=headers)
  print(json.dumps(response.json(), indent=2))
  ```

  ```bash CLI theme={null}
  olostep answer "When will React 30 be released?" --json-format '{"release_date":""}'
  ```
</CodeGroup>

Esto devolvería:

```json theme={null}
{
  "release_date": "NOT_FOUND"
}
```

## Precios

Las respuestas cuestan 20 créditos por solicitud.
