API v4
API v4 is the new version of the Gaard API. Its contract is a set of protobuf definitions. The OpenAPI specification and the SDKs come from these definitions, so they always agree with the API.
API v3.0 stays supported. You do not have to change your integration. See API v3.0 and its endpoints.
Protocols
Section titled “Protocols”Each RPC of API v4 is available in three forms, on the same host:
| Protocol | URL | Body |
|---|---|---|
| REST JSON | https://vision.gaard.ai/v4/... (see the OpenAPI specification) | JSON |
| Connect | https://vision.gaard.ai/gaard.<package>.<Service>/<Method> | JSON or protobuf |
| gRPC-Web | https://vision.gaard.ai/gaard.<package>.<Service>/<Method> | protobuf |
For example, the RPC Classify of ClassifyService in the package gaard.classify.v4 is POST /v4/classifications:classify in REST, and POST /gaard.classify.v4.ClassifyService/Classify with Connect. A Connect call with a JSON body must have the header Connect-Protocol-Version: 1.
The JSON field names are in lowerCamelCase, for example idempotencyKey. An enum value is its name, for example "STATE_DONE". A bytes field, for example the clip of Classify, is base64 in JSON.
OpenAPI specification
Section titled “OpenAPI specification”Download the OpenAPI 3 specification of API v4: openapi.yaml. Use it to generate a client in a language that has no SDK, or to import the API in a tool such as Postman.
Authentication
Section titled “Authentication”API v4 uses the same tokens as API v3.0. Put the token in the Authorization header:
Authorization: Bearer <your-api-token>Create an API token in the Gaard app at Settings > Platform > Integrations. API v4 does not accept basic authentication.
Limits
Section titled “Limits”- Rate limits. Each call has a cost, and a token and an organization each have a quota for each minute. The response headers
RateLimit-Limit,RateLimit-RemainingandRateLimit-Resetgive the state of the quota. A call above the quota gets the coderesource_exhausted(HTTP429), with the headerRetry-Afterin seconds. - Message size. A request to
ClassifyServicecan be up to 96 MiB in protobuf. In JSON, the clip can be up to 72 MiB before base64. A request to another service can be up to 4 MiB. - Deadline. Each RPC has a longest time. A call that takes longer gets the code
deadline_exceeded(HTTP504).
Errors
Section titled “Errors”An error has a code, a message, and sometimes details. A REST call gets the HTTP status of the code.
| Code | HTTP | Cause |
|---|---|---|
invalid_argument | 400 | A field of the request is not valid. The detail buf.validate.Violations names it. |
unauthenticated | 401 | The token is missing or not valid. |
permission_denied | 403 | The token cannot do this call, or cannot see this resource. |
not_found | 404 | The resource does not exist. |
resource_exhausted | 429 | The call is above a rate limit. Send it again after the time in Retry-After. |
deadline_exceeded | 504 | The call took longer than the deadline of the RPC. |
The SDKs are generated from the protobuf definitions on the Buf Schema Registry, for TypeScript and Go. Access to the SDKs is on request: contact us to get a registry token. The examples below use this token as BUF_TOKEN, and your Gaard API token as GAARD_TOKEN.
TypeScript
Section titled “TypeScript”Tell npm where the packages are, in the .npmrc file of your project:
@buf:registry=https://buf.build/gen/npm/v1///buf.build/gen/npm/v1/:_authToken=${BUF_TOKEN}Install the SDK and the Connect runtime:
npm install @buf/gaard-ai_gaard.bufbuild_es @connectrpc/connect @connectrpc/connect-nodeSend a clip and wait for its result:
import { readFileSync } from 'node:fs'import { createClient } from '@connectrpc/connect'import { createConnectTransport } from '@connectrpc/connect-node'import { ClassifyService } from '@buf/gaard-ai_gaard.bufbuild_es/gaard/classify/v4/classify_pb.js'
const transport = createConnectTransport({ baseUrl: 'https://vision.gaard.ai', httpVersion: '1.1', interceptors: [ (next) => (req) => { req.header.set('Authorization', `Bearer ${process.env.GAARD_TOKEN}`) return next(req) }, ],})
const client = createClient(ClassifyService, transport)const res = await client.classify({ content: readFileSync('cam03.mp4'), filename: 'cam03.mp4', wait: true,})const c = res.classificationconsole.log(c?.id, c?.state, c?.risk, c?.labels)Tell Go where the modules are, and give it the registry token:
export GOPRIVATE=buf.build/gen/goprintf 'machine buf.build\nlogin <your-registry-user>\npassword %s\n' "$BUF_TOKEN" >> ~/.netrcgo get buf.build/gen/go/gaard-ai/gaard/connectrpc/go@latestgo get buf.build/gen/go/gaard-ai/gaard/protocolbuffers/go@latestSend a clip and wait for its result:
package main
import ( "context" "fmt" "log" "net/http" "os"
"connectrpc.com/connect"
"buf.build/gen/go/gaard-ai/gaard/connectrpc/go/gaard/classify/v4/classifyv4connect" classifyv4 "buf.build/gen/go/gaard-ai/gaard/protocolbuffers/go/gaard/classify/v4")
func main() { clip, err := os.ReadFile("cam03.mp4") if err != nil { log.Fatal(err) } client := classifyv4connect.NewClassifyServiceClient(http.DefaultClient, "https://vision.gaard.ai") req := connect.NewRequest(&classifyv4.ClassifyRequest{ Content: clip, Filename: "cam03.mp4", Wait: true, }) req.Header().Set("Authorization", "Bearer "+os.Getenv("GAARD_TOKEN")) res, err := client.Classify(context.Background(), req) if err != nil { log.Fatal(err) } c := res.Msg.GetClassification() fmt.Println(c.GetId(), c.GetState(), c.GetRisk(), c.GetLabels())}Without an SDK
Section titled “Without an SDK”The same call in REST JSON. The clip is base64 in the field content:
curl -X POST https://vision.gaard.ai/v4/classifications:classify \ -H "Authorization: Bearer $GAARD_TOKEN" \ -H "Content-Type: application/json" \ -d "{\"filename\": \"cam03.mp4\", \"wait\": true, \"content\": \"$(base64 < cam03.mp4 | tr -d '\n')\"}"
