Inference Logoinference.sh

Agents

Chat with AI agents via REST.


Create Chat

POST /chats

Start a new agent chat session.

Request

FieldTypeRequiredDescription
agent_idstringNoTemplate agent ID
agent_version_idstringNoSpecific version
configobjectNoAd-hoc agent config

Template agent:

json
1{2  "agent_id": "agent_abc123",3  "agent_version_id": "ver_xyz789"4}

Ad-hoc agent:

json
1{2  "config": {3    "core_app_ref": "infsh/claude-sonnet-4@latest",4    "system_prompt": "You are a helpful assistant."5  }6}

Response

json
1{2  "id": "chat_abc123",3  "status": "active",4  "created_at": "2024-01-15T10:30:00Z"5}

Send Message

POST /chats/:id/messages

Send a message to an agent.

Request

FieldTypeRequiredDescription
contentstringYesMessage text
json
1{2  "content": "Hello, how can you help me?"3}

Response

json
1{2  "id": "msg_abc123",3  "role": "assistant",4  "content": "I'd be happy to help! What would you like to know?",5  "created_at": "2024-01-15T10:30:05Z"6}

Get Chat

GET /chats/:id

Get chat with message history.

Response

json
1{2  "id": "chat_abc123",3  "status": "active",4  "messages": [5    {"role": "user", "content": "Hello"},6    {"role": "assistant", "content": "Hi! How can I help?"}7  ]8}

Stop Chat

POST /chats/:id/stop

Stop an active response.


Submit Tool Result

POST /chats/:id/tool-result

Submit a tool execution result.

Request

json
1{2  "tool_call_id": "tc_abc123",3  "result": "72°F, Sunny"4}

cURL Example

bash
1# Create chat2curl -X POST https://api.inference.sh/chats \3  -H "Authorization: Bearer inf_your_key" \4  -H "Content-Type: application/json" \5  -d '{"agent_id": "agent_abc123"}'6 7# Send message8curl -X POST https://api.inference.sh/chats/chat_abc123/messages \9  -H "Authorization: Bearer inf_your_key" \10  -H "Content-Type: application/json" \11  -d '{"content": "Hello!"}'

we use cookies

we use cookies to ensure you get the best experience on our website. for more information on how we use cookies, please see our cookie policy.

by clicking "accept", you agree to our use of cookies.
learn more.