OpenModelOpenModel
SDKs & Libraries

cURL

Make API requests directly with cURL across all supported formats

cURL is the simplest way to test and interact with the OpenModel API. No SDK installation required — just use the command line.

Setup

Set your API key as an environment variable to avoid repeating it in every command:

export OPENMODEL_API_KEY="om-your-api-key"

OpenAI Format (Responses API)

Basic Request

curl https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "What is the meaning of life?"
  }'

Streaming

Use the -N flag (or --no-buffer) to disable output buffering, so you see events as they arrive:

curl -N https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Write a poem about the ocean.",
    "stream": true
  }'

With System Instructions

curl https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "instructions": "You are a helpful assistant that speaks like a pirate.",
    "input": "Tell me about the weather."
  }'

Multi-Turn Conversation

curl https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": [
      {"role": "user", "content": "My name is Alice."},
      {"role": "assistant", "content": "Hello Alice! How can I help you today?"},
      {"role": "user", "content": "What is my name?"}
    ]
  }'

Anthropic Format (Messages API)

Basic Request

curl https://api.openmodel.ai/v1/messages \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Explain recursion with a simple example."}
    ]
  }'

Streaming

curl -N https://api.openmodel.ai/v1/messages \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "stream": true,
    "messages": [
      {"role": "user", "content": "Write a short essay about artificial intelligence."}
    ]
  }'

With System Prompt

curl https://api.openmodel.ai/v1/messages \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "system": "You are a concise technical writer. Answer in bullet points.",
    "messages": [
      {"role": "user", "content": "What are the benefits of TypeScript over JavaScript?"}
    ]
  }'

Token Counting

curl https://api.openmodel.ai/v1/messages/count_tokens \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "user", "content": "How many tokens is this message?"}
    ]
  }'

Gemini Format

Basic Request

curl "https://api.openmodel.ai/v1beta/models/gemini-3.5-flash:generateContent?key=$OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "Explain the theory of relativity."}]}
    ]
  }'

Streaming

Use the streamGenerateContent endpoint with alt=sse:

curl -N "https://api.openmodel.ai/v1beta/models/gemini-3.5-flash:streamGenerateContent?alt=sse&key=$OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "Write a story about a time traveler."}]}
    ]
  }'

Multi-Turn Conversation

curl "https://api.openmodel.ai/v1beta/models/gemini-3.5-flash:generateContent?key=$OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"role": "user", "parts": [{"text": "What is 2 + 2?"}]},
      {"role": "model", "parts": [{"text": "2 + 2 = 4."}]},
      {"role": "user", "parts": [{"text": "Multiply that by 3."}]}
    ]
  }'

With System Instruction

curl "https://api.openmodel.ai/v1beta/models/gemini-3.5-flash:generateContent?key=$OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "systemInstruction": {
      "parts": [{"text": "You are a helpful coding assistant."}]
    },
    "contents": [
      {"parts": [{"text": "Write a Python function to reverse a string."}]}
    ]
  }'

Parsing Responses with jq

jq is a command-line JSON processor that makes it easy to extract specific fields from API responses.

Extract Text from OpenAI Response

curl -s https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Say hello in 3 languages."
  }' | jq -r '.output[] | select(.type == "message") | .content[] | .text'

Extract Text from Anthropic Response

curl -s https://api.openmodel.ai/v1/messages \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [
      {"role": "user", "content": "Say hello in 3 languages."}
    ]
  }' | jq -r '.content[0].text'

Extract Text from Gemini Response

curl -s "https://api.openmodel.ai/v1beta/models/gemini-3.5-flash:generateContent?key=$OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contents": [
      {"parts": [{"text": "Say hello in 3 languages."}]}
    ]
  }' | jq -r '.candidates[0].content.parts[0].text'

Extract Usage Statistics

# OpenAI format
curl -s https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Hello!"
  }' | jq '.usage'

# Anthropic format
curl -s https://api.openmodel.ai/v1/messages \
  -H "x-api-key: $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -H "anthropic-version: 2023-06-01" \
  -d '{
    "model": "claude-sonnet-4-6",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Hello!"}]
  }' | jq '.usage'

Tips

Save Response to File

curl -s https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gpt-5.4",
    "input": "Generate a JSON schema for a user profile."
  }' > response.json

Verbose Mode for Debugging

Use -v to see request and response headers, which is helpful for debugging authentication or connectivity issues:

curl -v https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-5.4", "input": "Hello"}'

Load Request Body from File

For complex requests, store the JSON body in a file:

# Create the request file
cat > request.json << 'EOF'
{
  "model": "gpt-5.4",
  "instructions": "You are a data analyst.",
  "input": "Analyze the trends in global renewable energy adoption over the past decade."
}
EOF

# Send the request
curl https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d @request.json

Set Timeouts

Use --max-time to set a total timeout and --connect-timeout for the connection phase:

curl --max-time 120 --connect-timeout 10 \
  https://api.openmodel.ai/v1/responses \
  -H "Authorization: Bearer $OPENMODEL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"model": "gpt-5.4", "input": "Hello"}'

Next Steps

On this page