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
- Put your OpenAI key in
OPENAI_API_KEYand your Doconda key (dashboard → API keys) inDOCONDA_API_KEY. - Turn each tool into OpenAI’s
functionformat. - Run the loop: while the reply has
tool_calls, run each tool and send the result back.
.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:readyorfailed. A failed document isn’t charged.- Links expire after 5 minutes; the model gets fresh ones with
get_document.
FAQ
Can I download the file on my server instead of passing the link?
Can I download the file on my server instead of passing the link?
Yes. With the
id the tool returns, doconda.documents.download(id, "docx") gives you the bytes.What if I want a PDF?
What if I want a PDF?
Ask for it in the message:
create_document takes format: "pdf" for the PDF alone. A Word file always comes with
its PDF.Does it work with Azure OpenAI or the Responses API?
Does it work with Azure OpenAI or the Responses API?
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.