GitLaw How-To guides
GitLaw Public API Reference
To use the GitLaw Public API, generate an API key in your GitLaw account settings, then send a POST request to https://api.git.law/api/v1/chat/ask with the key in the X-API-Key header, your instruction in the message field and the outputFileFormat you want (pdf or docx). The API processes the request and returns the AI's answer, plus any generated document, directly in the response.
Before you start: a GitLaw account and an API key. Prefer no-code? Use the Zapier integration instead.
What can I do with the GitLaw Public API?
The GitLaw Public API lets external services trigger contract generation and document analysis. Connect GitLaw to any system: your internal tools, Make, n8n, Pipedream, or anything else that can make HTTP requests.
- Generate contracts and legal documents via AI.
- Analyse existing documents by referencing a file already in GitLaw.
- Upload new files for analysis by including base64-encoded content.
- Continue existing chat conversations or start new ones.
How do I authenticate?
All API requests require an API key passed via the X-API-Key header:
X-API-Key: YOUR_API_KEY
Generate API keys in your GitLaw account settings. The full key is shown only once at creation, so store it securely. See Create, copy and delete GitLaw API keys.
The API endpoint
POST /api/v1/chat/ask
Send a message to generate or analyse a contract.
Request body:
{ "message": "Create an NDA between Acme Corp and Beta Inc", "outputFileFormat": "docx", "fileId": "file-123", "fileContent": "base64...", "fileName": "doc.docx", "chatId": "550e8400-e29b-41d4-a716-446655440000" }
| Parameter | Required | Description |
|---|---|---|
message | Yes | Your request or instruction for the AI |
outputFileFormat | Yes | Format of the returned document - pdf or docx |
chatId | No | Chat ID to continue an existing conversation. If omitted, a new chat is created |
fileId | No | ID of an existing file in GitLaw to use as context |
fileContent | No | Base64-encoded file content to upload as a new document |
fileName | No | Filename for the uploaded file (required when using fileContent) |
File handling rules:
- You can provide
fileId,fileContent+fileName, or neither, but not bothfileIdandfileContent. - If both
fileIdandfileContentare provided, the request is rejected with a400 Bad Requesterror. - If
fileContentis provided,fileNamemust also be included (and vice versa). - Use
fileIdfor files already in GitLaw; usefileContent+fileNameto upload a new file with your request.
The response
The API processes the request and returns the result directly:
{ "chatId": "550e8400-e29b-41d4-a716-446655440000", "answer": "I've created an NDA between Acme Corp and Beta Inc...", "fileId": "file_789", "fileContent": "base64...", "fileName": "nda.docx" }
| Field | Description |
|---|---|
chatId | The chat where the conversation took place (existing or newly created) |
answer | The AI's response text |
fileId | ID of the file used or created (if applicable) |
fileContent | Base64-encoded document content (if a document was generated) |
fileName | Filename of the returned document |
Example: create a contract
curl -X POST https://api.git.law/api/v1/chat/ask -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "outputFileFormat": "docx", "message": "Create an NDA between Acme Corp and Beta Inc" }'
Response:
{ "chatId": "550e8400-e29b-41d4-a716-446655440000", "answer": "I've created an NDA between Acme Corp and Beta Inc...", "fileId": "file_789", "fileContent": "UEsDBBQAAAAI...", "fileName": "nda.docx" }
Example: analyse an existing document
curl -X POST https://api.git.law/api/v1/chat/ask -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "outputFileFormat": "docx", "message": "Review this contract and identify any problematic clauses", "fileId": "file_existing_789" }'
Response:
{ "chatId": "550e8400-e29b-41d4-a716-446655440000", "answer": "I've reviewed the contract. Here are the key issues I identified:\n\n1. The liability clause in Section 4.2 is unusually broad...", "fileId": "file_existing_789" }
Example: upload and analyse a new file
curl -X POST https://api.git.law/api/v1/chat/ask -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "outputFileFormat": "docx", "message": "Summarize this contract", "fileContent": "UEsDBBQAAAAI...", "fileName": "vendor-agreement.docx" }'
Response:
{ "chatId": "550e8400-e29b-41d4-a716-446655440000", "answer": "Here is a summary of the vendor agreement...", "fileId": "file_new_456", "fileContent": "UEsDBBQAAAAI...", "fileName": "nda.docx" }
Example: continue a conversation
curl -X POST https://api.git.law/api/v1/chat/ask -H "X-API-Key: YOUR_API_KEY" -H "Content-Type: application/json" -d '{ "outputFileFormat": "docx", "chatId": "550e8400-e29b-41d4-a716-446655440000", "message": "Now add a non-compete clause to the NDA" }'
Response:
{ "chatId": "550e8400-e29b-41d4-a716-446655440000", "answer": "I've added a non-compete clause to the NDA...", "fileId": "file_789", "fileContent": "UEsDBBQAAAAI...", "fileName": "nda.docx" }
Error handling
| Error | Cause | Solution |
|---|---|---|
400 - Missing message | Required field not provided | Include a message in the request body |
400 - Both fileId and fileContent provided | These fields are mutually exclusive | Use one or the other, not both |
400 - fileContent without fileName | fileName is required when uploading a file | Include fileName alongside fileContent |
401 - Unauthorized | Invalid or expired API key | Check your API key is correct and not expired |
403 - Forbidden | The key may not act on this resource | Check the key's account and permissions |
404 - Invalid fileId | File doesn't exist or isn't accessible | Verify the file ID and your permissions |
413 - Payload Too Large | Decoded file over 1 MB (~1.4 MB base64) | Send a smaller file |
422 - Conversion failed | The document could not be converted | Check the file is a valid DOCX or PDF |
429 - Rate limited | Too many requests | Wait before retrying |
500 - Server error | Unexpected failure on our side | Retry, then contact support if it persists |
Best practices
- Store your API key securely: it is shown only once at creation and cannot be recovered.
- Use
chatIdto continue conversations: this preserves context from previous messages, producing better results. - Prefer
fileIdfor existing files: avoid re-uploading files that are already in GitLaw. - Handle errors gracefully: check HTTP status codes and parse error responses.
- Respect rate limits: back off when you receive a
429response.
Frequently asked questions
How do I authenticate with the GitLaw Public API?
Pass your API key in the X-API-Key header on every request. Keys are generated in your GitLaw account settings and shown only once at creation.
Can I upload a file and reference an existing file in the same request?
No. fileId and fileContent are mutually exclusive; providing both returns a 400 Bad Request. Use fileId for files already in GitLaw, or fileContent with fileName to upload a new one.
What should I check if requests fail?
Verify your API key is valid and not expired, ensure all required parameters are provided, check that fileId and fileContent are not used together, and contact GitLaw support if problems persist.
Related articles
Reviewed by the GitLaw team. Last updated 29 July 2026.