> ## 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.

# Gemini API: generate a DOCX (Word) file

> Declare doconda.tools() as Gemini functions: the model creates an editable Word .docx (or a PowerPoint) and gives you the download link.

To generate a DOCX (Word) file with the Gemini API, declare `doconda.tools()` as Gemini functions. When you ask for a
document, Gemini calls `create_document` with `format: "docx"` and you get an editable Word file and its PDF, with their
download links. The same works for a PowerPoint (`pptx`) or an Excel file (`xlsx`).

## Steps

1. Have your Gemini API key in the environment (`GEMINI_API_KEY`), or use Vertex AI (below).
2. Put your Doconda API key (dashboard → **API keys**) in `DOCONDA_API_KEY`.
3. Declare the tools and run the loop: while Gemini asks for functions, run them and hand back the result.

<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: "Make me a Word report on remote work" }] }]

  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="Make me a Word report on remote work")])]

  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` in Python) takes each tool's JSON Schema as is.

**On Vertex AI** it's the same code: `new GoogleGenAI({ vertexai: true, project: "my-project", location: "europe-west1" })`
in TypeScript or `genai.Client(vertexai=True, project="my-project", location="europe-west1")` in Python, with the
credentials from your Google Cloud environment.

## What you get back

```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."
}
```

* A truly editable Word file: the look lives in the document's styles (Normal, Heading 1…), plus its PDF.
* `status`: `ready`, `ready_with_warnings`, `needs_review` or `failed` (not charged).
* Links expire after 5 minutes; the agent gets fresh ones with `get_document`.

## FAQ

<AccordionGroup>
  <Accordion title="How do I generate a PowerPoint with Gemini?">
    The same way: ask for a presentation (*"Create a 5-slide presentation on our quarterly results"*) and Gemini calls
    `create_document` with `format: "pptx"`. You get a 16:9 `.pptx` with native charts and its PDF.
  </Accordion>

  <Accordion title="Can I use MCP instead of declaring the functions?">
    Yes, with `mcpToTool` from `@google/genai` (experimental) and the remote server `https://api.eu.doconda.com/mcp`.
    See [Gemini](/en/agents/gemini).
  </Accordion>

  <Accordion title="Can it edit a Word file I already have?">
    Yes: the agent uploads the file with `upload_file` and calls `edit_document`, which changes only what you ask.
  </Accordion>

  <Accordion title="How much does it cost?">
    You pay per delivered document; failed ones are not charged. See [pricing](/en/guides/account#pricing).
  </Accordion>
</AccordionGroup>

## Keep reading

* [Gemini](/en/agents/gemini) and [Google Vertex AI](/en/agents/vertex): the full guides.
* [Excel from Gemini on Vertex AI](/en/answers/vertex-gemini-excel).
* [Quickstart](/en/quickstart).


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