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

ParameterRequiredDescription
messageYesYour request or instruction for the AI
outputFileFormatYesFormat of the returned document - pdf or docx
chatIdNoChat ID to continue an existing conversation. If omitted, a new chat is created
fileIdNoID of an existing file in GitLaw to use as context
fileContentNoBase64-encoded file content to upload as a new document
fileNameNoFilename for the uploaded file (required when using fileContent)

File handling rules:

  • You can provide fileId, fileContent + fileName, or neither, but not both fileId and fileContent.
  • If both fileId and fileContent are provided, the request is rejected with a 400 Bad Request error.
  • If fileContent is provided, fileName must also be included (and vice versa).
  • Use fileId for files already in GitLaw; use fileContent + fileName to 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" }

FieldDescription
chatIdThe chat where the conversation took place (existing or newly created)
answerThe AI's response text
fileIdID of the file used or created (if applicable)
fileContentBase64-encoded document content (if a document was generated)
fileNameFilename 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

ErrorCauseSolution
400 - Missing messageRequired field not providedInclude a message in the request body
400 - Both fileId and fileContent providedThese fields are mutually exclusiveUse one or the other, not both
400 - fileContent without fileNamefileName is required when uploading a fileInclude fileName alongside fileContent
401 - UnauthorizedInvalid or expired API keyCheck your API key is correct and not expired
403 - ForbiddenThe key may not act on this resourceCheck the key's account and permissions
404 - Invalid fileIdFile doesn't exist or isn't accessibleVerify the file ID and your permissions
413 - Payload Too LargeDecoded file over 1 MB (~1.4 MB base64)Send a smaller file
422 - Conversion failedThe document could not be convertedCheck the file is a valid DOCX or PDF
429 - Rate limitedToo many requestsWait before retrying
500 - Server errorUnexpected failure on our sideRetry, then contact support if it persists

Best practices

  1. Store your API key securely: it is shown only once at creation and cannot be recovered.
  2. Use chatId to continue conversations: this preserves context from previous messages, producing better results.
  3. Prefer fileId for existing files: avoid re-uploading files that are already in GitLaw.
  4. Handle errors gracefully: check HTTP status codes and parse error responses.
  5. Respect rate limits: back off when you receive a 429 response.

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.

Sign up to source, customize, and store contracts for free

Sign Up