Goatlab API Docs

Set user context

POST
/v1/context

This endpoint creates or updates the context information for a user. The context is used to personalize LLM responses.

Behavior:

  • If the user context does not exist, it will be created
  • If the user context already exists, only the provided fields will be updated
  • Fields not included in the request body will retain their current values
  • To clear a field, send null as the value

Scoped Requests (External Systems): When using a scoped API key, the endpoint automatically handles user provisioning:

  • If the user doesn't exist, it will be created

Non-Scoped Requests: When using a non-scoped API key:

  • The user must already exist in the system
  • Returns 403 if the user is not found

Validation:

  • At least one of role or personalPreference must be provided
  • role has a maximum length of 250 characters
  • personalPreference has a maximum length of 500 characters

Authorization

ApiTokenAuth PRODUCT
x-api-key<token>

API Key with role based permission

In: header

Scope: PRODUCT

Header Parameters

x-user-id*string

The ID of the user to set context for

Request Body

application/json

The user context fields to create or update

TypeScript Definitions

Use the request body type in TypeScript.

Request body for setting user context

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X POST "https://example.com/v1/context" \  -H "x-user-id: string" \  -H "Content-Type: application/json" \  -d '{    "role": "Software Engineer",    "personalPreference": "Prefers concise technical answers"  }'
{
  "userId": "scope_550e8400-e29b-41d4-a716-446655440000",
  "role": "Software Engineer",
  "personalPreference": "Prefers concise technical answers",
  "createdAt": "2026-04-24T10:30:00.000Z",
  "updatedAt": "2026-04-24T10:30:00.000Z"
}
{
  "message": {
    "description": "Validation failed",
    "errors": [
      {
        "path": "body",
        "message": "At least one of role or personalPreference must be provided"
      }
    ]
  }
}
{
  "message": "Unauthorized"
}
{
  "message": "User user-123 does not exist or is not accessible with this API key"
}
{
  "message": "Internal Server Error"
}