Skip to main content
The OpenAI API returns text, not files, so give the model a tool that makes them. Pass doconda.tools() as tools in chat.completions.create and run each tool call the model makes: create_document returns links to the Word file (.docx) and its PDF.

Return a Word file from Chat Completions

  1. Put your OpenAI key in OPENAI_API_KEY and your Doconda key (dashboard → API keys) in DOCONDA_API_KEY.
  2. Turn each tool into OpenAI’s function format.
  3. Run the loop: while the reply has tool_calls, run each tool and send the result back.
The last message is the model’s reply with the .docx and PDF links. A tool’s run() never throws for an API error: it returns { "error": "…", "message": "…" }, which the model reads and explains.

Choose an agent or a direct call

The direct call costs €0.20 at the default level, since Doconda only lays out your text. From a prompt, it’s €0.50.

What you get back

create_document returns this to the model:
  • An editable Word file: the look lives in its styles (Normal, Heading 1…), so text added later keeps the design.
  • status: ready or failed. A failed document isn’t charged.
  • Links expire after 5 minutes; the model gets fresh ones with get_document.

FAQ

Ask for it in the message: create_document takes format: "pdf" for the PDF alone. A Word file always comes with its PDF.
Yes. With Azure, the same code runs on AzureOpenAI(); see Azure OpenAI. The tool definitions are plain JSON Schema, so they fit any function-calling API.
For the full setup, also with OpenAI Codex, see OpenAI.