Request Labeling

Add metadata to your API requests using the x-glama-metadata HTTP header. Attached labels help track and filter requests in logs dashboard.

Overview

  • Labels allow you to associate custom metadata with requests. Common use cases include user IDs, team names, environment names, and other information relevant to your request.
  • Labels appear in your logs, allowing for detail inspection, categorization and troubleshooting.
  • Use metadata to effectively search and filter through your requests.

How to Use

The x-glama-metadata header uses metadata in the form of JSON { "labels": [ { "key": "foo", "value": "bar" } ] }.

Format Rules

  • Keys must be alphanumeric and can include -, _, or ..
  • Value must be a string, number or a boolean.
  • The header must not exceed 8KB, and keys must be unique.

Examples

Using cURL

curl -X POST https://glama.ai/gateway/openai/v1/chat/completions \ -H 'Content-Type: application/json' \ -H 'X-Glama-Metadata: { "labels": [ { "key": "foo", "value": "bar" } ] }' \ -d '{ "model": "gpt-4", "messages": [ {"role": "user", "content": "Hello, World!"} ] }'

Using OpenAI SDK

import { OpenAI } from 'openai' const openai = new OpenAI({ baseURL: 'https://glama.ai/api/gateway/openai/v1', apiKey: GLAMA_API_KEY, }); await openai.chat.completions.create( { messages: [ { role: 'user', content: 'Hello!' } ], model: 'anthropic/claude-2', }, headers: { "x-glama-metadata": JSON.stringify({ labels: [ { key: 'foo', value: 'bar' } ] }), }, );

Log Filtering

Filter logs at /logsusing labels.

Examples:

  • environment=production
  • user_id=12345
  • Multiple Filters: environment=staging and priority=high