I’ve implemented a Node.js server to interact with the Cody Chat API, using Cody Chat to explain me how. While the connection and authentication work (200 status), the API consistently reports “max_tokens: Field required” despite the parameter being present in the request.
Setup details:
- Endpoint: https://sourcegraph.com/.api/completions/stream
- Method: POST
- Headers: Content-Type: application/json, Accept: text/event-stream
- Valid authentication token (confirmed working)
Request body:
{
“messages”: [{
“speaker”: “human”,
“text”: “test”
}],
“max_tokens”: 2000
}
parameters like temperature: 0.2, top_k: 1, top_p: 1 were used too, but are considered optional now, right?
The API returns 200 but then streams:
event: error
data: {“error”:“Sourcegraph Cody Gateway: unexpected status code 400: {"type":"error","error":{"type":"invalid_request_error","message":"max_tokens: Field required"}}”}
Tested variations:
- Different max_tokens values (500, 1000, 2046)
- Various parameter formats (max_tokens, maxTokens)
- Different request structures
Full response headers and rate limiting info available if needed.
Has anyone successfully implemented the Cody Chat API in Node.js?