cURL Examples
โ ๏ธ BETA: Our API is in beta. Share your feedback!
Command-line examples for GMTech's API using cURL.
Basic Chat
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer gmtech_your_api_key" \
-d '{
"model": "gpt-4-turbo",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "What is cURL?"}
]
}'
Different Models
OpenAI GPT-4
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Claude
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "claude-3-5-sonnet-20241022",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Gemini
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gemini-1.5-pro",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Streaming
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [{"role": "user", "content": "Tell me a story"}],
"stream": true
}'
Image Generation
curl https://app.gmtech.com/api/v1/images/generations \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "dall-e-3",
"prompt": "A futuristic city",
"size": "1024x1024"
}'
List Available Models
curl https://app.gmtech.com/api/v1/models \
-H "Authorization: Bearer $GMTECH_API_KEY"
Using Environment Variable
# Set your API key
export GMTECH_API_KEY="gmtech_your_api_key"
# Use in requests
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Pretty JSON Output
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}' | jq '.'
Save to File
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}' -o response.json
Error Handling
# Check response status
curl -w "%{http_code}" https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d '{
"model": "gpt-4-turbo",
"messages": [{"role": "user", "content": "Hello!"}]
}'
Shell Script Example
#!/bin/bash
# chat.sh - Simple GMTech API script
GMTECH_API_KEY="gmtech_your_key"
MODEL="${1:-gpt-3.5-turbo}"
MESSAGE="${2:-Hello!}"
curl https://app.gmtech.com/api/v1/chat/completions \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GMTECH_API_KEY" \
-d "{
\"model\": \"$MODEL\",
\"messages\": [{\"role\": \"user\", \"content\": \"$MESSAGE\"}]
}" | jq -r '.choices[0].message.content'
# Usage: ./chat.sh gpt-4-turbo "What is AI?"
Next Steps
- Python Examples - Python integration
- JavaScript Examples - Frontend and Node.js
- API Overview - Complete API docs
Need help? Contact support