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

# API de Gemini: generar un archivo DOCX (Word)

> Declara doconda.tools() como funciones de Gemini: el modelo crea un Word .docx (o un PowerPoint) editable y te da el enlace de descarga.

Para generar un archivo DOCX (Word) con la API de Gemini, declara `doconda.tools()` como funciones de Gemini. Cuando
pides un documento, Gemini llama a `create_document` con `format: "docx"` y recibes un Word editable y su PDF, con sus
enlaces de descarga. Lo mismo vale para un PowerPoint (`pptx`) o un Excel (`xlsx`).

## Pasos

1. Ten tu key de la API de Gemini en el entorno (`GEMINI_API_KEY`), o usa Vertex AI (abajo).
2. Guarda tu API key de Doconda (panel → **API keys**) en `DOCONDA_API_KEY`.
3. Declara las herramientas y ejecuta el bucle: mientras Gemini pida funciones, las ejecutas y le devuelves el resultado.

<CodeGroup>
  ```ts TypeScript theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  // npm install @google/genai @doconda/sdk
  import { type Content, GoogleGenAI } from "@google/genai"
  import { Doconda } from "@doconda/sdk"

  const ai = new GoogleGenAI({})
  const tools = new Doconda().tools()
  const contents: Content[] = [{ role: "user", parts: [{ text: "Hazme un informe en Word sobre el teletrabajo" }] }]

  while (true) {
    const res = await ai.models.generateContent({
      model: "gemini-3.8-flash",
      contents,
      config: { tools: [{ functionDeclarations: tools.map((t) => ({ name: t.name, description: t.description, parametersJsonSchema: t.inputSchema })) }] },
    })
    if (!res.functionCalls?.length) {
      console.log(res.text)
      break
    }
    contents.push(res.candidates![0].content!)
    const parts = await Promise.all(
      res.functionCalls.map(async (call) => ({
        functionResponse: { name: call.name, response: { result: await tools.find((t) => t.name === call.name)!.run(call.args ?? {}) } },
      })),
    )
    contents.push({ role: "user", parts })
  }
  ```

  ```python Python theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
  # pip install google-genai doconda
  from doconda import Doconda
  from google import genai
  from google.genai import types

  client = genai.Client()
  tools = Doconda().tools()
  config = types.GenerateContentConfig(
      tools=[types.Tool(function_declarations=[
          types.FunctionDeclaration(name=t.name, description=t.description, parameters_json_schema=t.input_schema) for t in tools
      ])]
  )
  contents = [types.Content(role="user", parts=[types.Part.from_text(text="Hazme un informe en Word sobre el teletrabajo")])]

  while True:
      res = client.models.generate_content(model="gemini-3.8-flash", contents=contents, config=config)
      if not res.function_calls:
          break
      contents.append(res.candidates[0].content)
      parts = [
          types.Part.from_function_response(name=c.name, response={"result": next(t for t in tools if t.name == c.name).run(dict(c.args or {}))})
          for c in res.function_calls
      ]
      contents.append(types.Content(role="user", parts=parts))

  print(res.text)
  ```
</CodeGroup>

`parametersJsonSchema` (`parameters_json_schema` en Python) acepta el JSON Schema de cada herramienta tal cual.

**En Vertex AI** es el mismo código: `new GoogleGenAI({ vertexai: true, project: "mi-proyecto", location: "europe-west1" })`
en TypeScript o `genai.Client(vertexai=True, project="mi-proyecto", location="europe-west1")` en Python, con las
credenciales de tu entorno de Google Cloud.

## Qué devuelve

```json theme={"theme":{"light":"github-light","dark":"github-dark-dimmed"}}
{
  "id": "doc_01JAB3…",
  "format": "docx",
  "status": "ready",
  "links": { "docx": "https://…", "pdf": "https://…" },
  "links_note": "Links expire in 5 minutes: call get_document for fresh ones."
}
```

* Un Word editable de verdad: el aspecto va en los estilos del documento (Normal, Título 1…), y su PDF.
* `status`: `ready`, `ready_with_warnings`, `needs_review` o `failed` (no se cobra).
* Los enlaces caducan a los 5 minutos; el agente pide otros con `get_document`.

## Preguntas frecuentes

<AccordionGroup>
  <Accordion title="¿Cómo genero un PowerPoint con Gemini?">
    Igual: pide una presentación (*"Crea una presentación de 5 diapositivas sobre nuestros resultados del trimestre"*) y
    Gemini llama a `create_document` con `format: "pptx"`. Recibes un `.pptx` 16:9 con gráficos nativos y su PDF.
  </Accordion>

  <Accordion title="¿Puedo usar MCP en vez de declarar las funciones?">
    Sí, con `mcpToTool` de `@google/genai` (experimental) y el servidor remoto `https://api.eu.doconda.com/mcp`. Ver
    [Gemini](/agents/gemini).
  </Accordion>

  <Accordion title="¿Puede editar un Word que ya tengo?">
    Sí: el agente sube el fichero con `upload_file` y llama a `edit_document`, que cambia solo lo que pides.
  </Accordion>

  <Accordion title="¿Cuánto cuesta?">
    Pagas por documento entregado; los que fallan no se cobran. Ver [precios](/guides/account#precios).
  </Accordion>
</AccordionGroup>

## Sigue leyendo

* [Gemini](/agents/gemini) y [Google Vertex AI](/agents/vertex): las guías completas.
* [Excel desde Gemini en Vertex AI](/answers/vertex-gemini-excel).
* [Quickstart](/quickstart).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.